Master Chef wants to select a new manager for his resturant . All Chefs are seated in one room, Chefs are made to sit in m rows and n cols.Feedback-points of all Chef are given. All the Highest feedback-points Chefs of each row are selected.Next, all the lowest feedback-points Chefs of each column are selected. Now Master-Chef need to find weather there exist any Chef which is highest pointer in a row and lowest in column. If any Chef exists with this criteria, He is selected as new Manager .
First line contains T, the number of test cases.
For each test case ,
First line contain , the row m and column n of Chefs.
The following m rows have n numbers separated by space.These number represent feedback-points of Chefs.
A single number, the point of the chef who is selected as new manager. if new manager can't be selected print -1.
Input: 2 3 2 4 5 3 1 2 4 3 4 10 9 8 7 12 20 1 3 13 7 2 14 Output: -1 10
|Time Limit:||0.1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions