Find Elements Largest in Row Smallest in Column
Write an algorithm which finds out the elements which are largest in a row and smallest in a column in a matrix.
Input
The first line of input consists of two space-separated integers- matrix_row and matrix_col, representing the number of rows in the matrix (N) and the number of columns in the matrix (M), respectively.
The next M lines consist of N space-separated integers representing the elements of the matrix.
Output
Print a number which is largest in a row and smallest in a column in the given matrix. If no element is found print '-1'.
Note
Each number in the matrix is a non-negative integer.
1Example 1
Constraints
Limits and guarantees your solution can rely on.
1 ≤ N, M ≤ 1000