Maze maximum

4.3

23 votes
, Algorithms, Binary Search, C++
Problem

You are given a 2-D matrix A of size N×M, its elements are integers. We will assume that the rows of the matrix are numbered from top to bottom from 1 to N, the columns are numbered from left to right from 1 to M. We will denote the element on the intersecting of the i-th row and the j-th column as Ai,j.

Find the maximum possible value X, such that:

  • There exists at least one row and one column where all the value of all the elements X.

Input format

  • First line contains two space-separated integers N,M - the number of rows and columns of the matrix.
  • Next N lines contains M space-separated integers denoting the matrix.

Output format

Print the value of X.

Constraints

1N×M1061Ai,j109

 

Sample Input
3 3
2 1 3
4 2 4
5 9 6
Sample Output
3
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

If X=3, all the elements in row 3 and column 3 satisfy the given conditions. It can be proved that X cannot be greater than 3.

Editor Image

?