Our Chef is very happy that his son was selected for training in one of the finest culinary schools of the world.
So he and his wife decide to buy a gift for the kid as a token of appreciation.
Unfortunately, the Chef hasn't been doing good business lately, and is in no mood on splurging money.
On the other hand, the boy's mother wants to buy something big and expensive.
To settle the matter like reasonable parents, they play a game.

They spend the whole day thinking of various gifts and write them down in a huge matrix.
Each cell of the matrix contains the gift's cost.
Then they decide that the mother will choose a row number r while the father will choose a column number c,
the item from the corresponding cell will be gifted to the kid in a couple of days. 

The boy observes all of this secretly.
He is smart enough to understand that his parents will ultimately choose a gift whose cost is smallest in its row,
but largest in its column.
If no such gift exists, then our little chef has no option but to keep guessing.
As the matrix is huge, he turns to you for help.

He knows that sometimes the gift is not determined uniquely even if a gift exists whose cost is smallest in its row,
but largest in its column.
However, since the boy is so smart, he realizes that the gift's cost is determined uniquely.
Your task is to tell him the gift's cost which is smallest in its row,
but largest in its column, or to tell him no such gift exists.

-----Input-----
First line contains two integers R and C, the number of rows and columns in the matrix respectively. Then follow R lines, each containing C space separated integers - the costs of different gifts.

-----Output-----
Print a single integer - a value in the matrix that is smallest in its row but highest in its column. If no such value exists, then print "GUESS" (without quotes of course) 

-----Constraints-----
1 <= R, C <= 100 
All gift costs are positive and less than 100000000 (10^8) 

-----Example 1-----
Input:
2 3
9 8 8
2 6 11

Output:
8

-----Example 2-----
Input:
3 3
9 8 11
2 6 34
5 9 11

Output:
GUESS

-----Example 3-----
Input:
2 2
10 10
10 10

Output:
10

-----Explanation of Sample Cases-----
Example 1: The first row contains 9, 8, 8. Observe that both 8 are the minimum. Considering the first 8, look at the corresponding column (containing 8 and 6). Here, 8 is the largest element in that column. So it will be chosen.
Example 2: There is no value in the matrix that is smallest in its row but largest in its column.
Example 3: The required gift in matrix is not determined uniquely, but the required cost is determined uniquely.

Difficulty: interview

Starter code:

Solutions:
try:
    r, c = map(int, input().split())
    mat = []
    for i in range(r):
        arr=list(map(int, input().split()))
        mat.append(arr)
    flag=0
    arr1=[]
    for x in range(c):
        arr = []
        for j in range(r):
            arr.append(mat[j][x])
        arr1.append(arr)
    i=0
    for i in range(r):
        for j in range(c):
            if mat[i][j]==max(arr1[j]) and mat[i][j]==min(mat[i]):
                flag=1
                print(mat[i][j])
                break
        if flag==1:
            break
    if flag==0:
        print("GUESS")
except:
    pass

# cook your dish here
r,c=map(int,input().split())
mi=[]
m=[]
for i in range(r):
    s=list(map(int,input().split()))
    mi.append(min(s))
    m.append(s)
n=[]
for i in range(c):
    x=[]
    for j in range(r):
        x.append(m[j][i])
    n.append(max(x))
flag=0
for i in mi:
    if i in n:
        print(i)
        flag=1 
        break
if flag==0:
    print('GUESS')

        
    

r,c=map(int,input().split())
mat=[]
l=[]
flag=0
for i in range(r):
    t_1=list(map(int,input().split()))
    l.append(min(t_1))
    mat.append(t_1)
r_1=[]
for i in range(c):
    x=[]
    for j in range(r):
        x.append(mat[j][i])
    r_1.append(max(x))
for i in l:
    if i in r_1:
        print(i)
        flag=1
        break
if flag==0:
    print('GUESS')


# cook your dish here
r,c=map(int, input().split())
k=[]
for _ in range(r):
    a=[]
    a=list(map(int, input().split()))
    k.append(a)
rmin=[]
cmax=[]
for i in range(r):
    rmin.append(min(k[i]))
for j in range(c):
    b = k[0][j]
    for i in range(r):
        if b<k[i][j]:
            b = k[i][j]
    cmax.append(b)
if(set(rmin).intersection(set(cmax))):
    print(*set(rmin).intersection(set(cmax)))
else:
    print('GUESS')


# cook your dish here
r, c = map(int, input().split())
k = []

for i in range(r):
    a = []
    a = list(map(int, input().split()))
    k.append(a)

rmin = []
cmax = []

for i in range(r):
    rmin.append(min(k[i]))

for j in range(c):
    b = k[0][j]
    for i in range(r):
        if b<k[i][j]:
            b = k[i][j]
    cmax.append(b)

if(set(rmin).intersection(set(cmax))):
    print(*set(rmin).intersection(set(cmax)))
else:
    print('GUESS')


r, c = map(int, input().split())
k = []

for i in range(r):
    a = []
    a = list(map(int, input().split()))
    k.append(a)

rmin = []
cmax = []

for i in range(r):
    rmin.append(min(k[i]))

for j in range(c):
    b = k[0][j]
    for i in range(r):
        if b<k[i][j]:
            b = k[i][j]
    cmax.append(b)

if(set(rmin).intersection(set(cmax))):
    print(*set(rmin).intersection(set(cmax)))
else:
    print('GUESS')

# print(k)
# print(rmin)
# print(cmax)


# cook your dish here



"""


"""

def check_in_column(arr , value , index , X):
    for i in range(X):
        if arr[i][index]>value:
            return False
    return True        

def result(arr , X , Y):
    for i in range(X):
        s = min(arr[i])
        for j in range(Y):
            if (arr[i][j] == s):
                if(check_in_column(arr , s , j , X)):
                    return s
    return "GUESS"

X , Y = [int(d) for d in input().split()]
arr = []
for i in range(X):
    arr.append([int(d) for d in input().split()])


print(result(arr,X,Y))


# cook your dish here
r,c=list(map(int,input().split(" ")))

mat=[]
small_mat=[]
result="GUESS"

for i in range(r):
    data=list(map(int,input().split(" ")))
    small_mat.append(min(data))
    mat.append(data)

for i in range(r):
    for j in range(c):
        if mat[i][j]==small_mat[i]:
            temp_data=[]
            for k in range(r):
                temp_data.append(mat[k][j])
            
            if max(temp_data)==small_mat[i]:
                result=small_mat[i]
                break
print(result)

# cook your dish here
r,c=list(map(int,input().split(" ")))

mat=[]
small_mat=[]
#slc=[]
result="GUESS"

for i in range(r):
    data=list(map(int,input().split(" ")))
    small_mat.append(min(data))
    mat.append(data)

#print(small_mat)

for i in range(r):
    for j in range(c):
        if mat[i][j]==small_mat[i]:
            temp_data=[]
            for k in range(r):
                temp_data.append(mat[k][j])
            
            if max(temp_data)==small_mat[i]:
                result=small_mat[i]
                break
print(result)

from numpy import *
r,c=map(int,input().split())
x=[]
for i in range(r):
    y=list(map(int,input().split()))
    x.append(y)
x=array(x)
b=x.transpose()
for i in x:
    c=[]
    i=list(i)
    a=min(i)
    ab=0
    for k in range(len(i)):
        if(i[k]==a):
            c.append(k)
    for k in c:
        d=max(list(b[k]))
        if(a==d):
            print(a)
            ab+=1
            break
    if(ab>0):
        break
else:
    print("GUESS")

r,c=map(int,input().split())
mat=[]
rmin=[]
cmax=[]
d={}
f=0
for i in range(r):
    l=list(map(int,input().split()))
    mat.append(l)
for i in range(r):
    x=min(mat[i])
    rmin.append(x)
for i in range(c):
    x=[]
    for j in range(r):
        x.append(mat[j][i])
    cmax.append(max(x))
for i in rmin:
    if(i in cmax):
        print(i)
        f=1
        break
if(f==0):
    print("GUESS")

r,c=map(int,input().split())
mat=[]
rmin=[]
cmax=[]
d={}
f=0
for i in range(r):
    l=list(map(int,input().split()))
    mat.append(l)
for i in range(r):
    x=min(mat[i])
    rmin.append(x)
for i in range(c):
    x=[]
    for j in range(r):
        x.append(mat[j][i])
    cmax.append(max(x))
for i in rmin:
    if(i in cmax):
        print(i)
        f=1
        break
if(f==0):
    print("GUESS")

# cook your dish here
from sys import stdin,stdout

r,c = map(int,stdin.readline().strip().split())
gift_list = [list(map(int,stdin.readline().strip().split())) for _ in range(r)]

max_list = [max(i) for i in zip(*gift_list)]
# print(max_list)
found=False
for i in range(r):
    min_row = min(gift_list[i])
    for j in range(c):
        if gift_list[i][j]==min_row and gift_list[i][j]==max_list[j]:
            print(gift_list[i][j])
            found=True
            break
    if found:
        break
else:
    print("GUESS")
            

# cook your dish here
n,m = map(int, input().strip().split())
mat=[]
for _ in range (n):
    mat.append(list(map(int,input().strip().split())))



def rmin(mat,r):
    row=mat[r]
    rm=min(row)
    return(rm)

def cmax(mat,c):
    col=list(_[c] for _ in mat)
    cm=max(col)
    return(cm)

rm=list(rmin(mat,_) for _ in range(n))

cm=list(cmax(mat,_) for _ in range(m))

num = 0
for _ in range(n):
    for __ in range(m):
        if mat[_][__] == rm[_]:
            if mat[_][__] == cm[__]:
                num = mat[_][__]
                break
    if num!=0:
        break
if num!=0:
    print(num)
else:
    print("GUESS")

r, c=map(int, input().strip().split())
main=[]
row=[]
col=[]
for j in range(r):
    a=list(map(int, input().strip().split()))    
    main.append(a)
    row.append(min(a))
count=0
for i in range(c):
    max=0
    for k in range(r):
        if(max<main[k][i]):
            max=main[k][i]
    col.append(max)
for i in range(r):
    n=row[i]
    for j in range(c):
        if(main[i][j]==n and col[j]==n):
            count=1
            break
    if(count==1):
        print(n)
        break
if(count==0):
    print("GUESS")

r,c = (map(int, input().strip().split()))

matrix = []
minRow = []
for i in range(r):
    arr = list(map(int, input().strip().split()))
    minRow.append( min(arr) )
    matrix.append(arr)
flag=1
maxCol = []
for j in range(c):
    maxi = -1
    for i in range(r):
        maxi = max(maxi, matrix[i][j])
    maxCol.append( maxi )

for i in range(r):
    n = minRow[i]
    
    for j in range(c):
        if matrix[i][j] == n and maxCol[j] == n:
           
            flag=0
            break
    if flag==0:
        break

if flag==0:
    
    print(n)
else:
    print("GUESS")


r,c = (map(int, input().strip().split()))



matrix = []
minRow = []
for i in range(r):
    arr = list(map(int, input().strip().split()))
    minRow.append( min(arr) )
    matrix.append(arr)
flag=1
maxCol = []
for j in range(c):
    maxi = -1
    for i in range(r):
        maxi = max(maxi, matrix[i][j])
    maxCol.append( maxi )

for i in range(r):
    n = minRow[i]
    
    for j in range(c):
        if matrix[i][j] == n and maxCol[j] == n:
           
            flag=0
            break
    if flag==0:
        break

if flag==0:
    
    print(n)
else:
    print("GUESS")

def __starting_point():
    ROWS, COLS = list(map(int, input().strip().split()))

    giftCost = set()

    matrix = []
    minRow = []
    for i in range(ROWS):
        arr = list(map(int, input().strip().split()))
        minRow.append( min(arr) )
        matrix.append(arr)

    maxCol = []
    for j in range(COLS):
        maxi = -1
        for i in range(ROWS):
            maxi = max(maxi, matrix[i][j])
        maxCol.append( maxi )

    for i in range(ROWS):
        n = minRow[i]
        if n in giftCost:
            continue
        for j in range(COLS):
            if matrix[i][j] == n and maxCol[j] == n:
                giftCost.add(n)
            if len(giftCost) > 1:
                break
        if len(giftCost) > 1:
            break

    if len(giftCost) == 1:
        for n in giftCost:
            print(n)
    else:
        print("GUESS")
__starting_point()

n,m = map(int, input().split())
min_lst = []
max_lst = [[]]*m
mx = [0]*m
for r in range(n):
    tmp = list(map(int,input().split()))
    mn = tmp[0]
    tmp_lst = []
    j = 0
    for i in tmp:
        if i>mx[j]:
            mx[j] = i
            max_lst[j] = [(r,j,i)]
        elif i==mx[j]:
            max_lst[j].append((r,j,i))
        if i<mn:
            mn = i
            tmp_lst = [(r,j,i)]
        elif i==mn:
            tmp_lst.append((r,j,i))
        j+=1  
    min_lst.extend(tmp_lst)
flg = False
for i in max_lst:
    for j in i:
        if j in min_lst:
            print(j[2])
            flg = True
            exit(0)
if not flg:
    print("GUESS")

R,C = map(int,input().split())
MAT = []
for r in range(R):
    MAT.append(list(map(int,input().split())))

colMax = []

for c in range(C):
    maxi=-1
    for r in range(R):
        if MAT[r][c]>maxi:
            maxi=MAT[r][c]
    colMax.append(maxi)

rowMin = []
for r in range(R):
    mini=MAT[r][0]
    for c in range(1,C):
        if MAT[r][c]<mini:
            mini=MAT[r][c]
    rowMin.append(mini)

noGuess=False
element=-1
for i in rowMin:
    if i in colMax:
        element=i
        noGuess=True
        break

if(noGuess):
    print(element)
else:
    print("GUESS")

row, col = map(int, input().split())
m = [[int(x) for x in input().split()] for y in range(row)]

minL = []
maxL = []
ans = []

for i in range(row):
    minVal = 10**12
    for j in range(col):
        if(minVal>=m[i][j]):
            minVal = m[i][j]
    minL.append(minVal)

for i in range(col):
    maxVal = 0
    for j in range(row):
        if(maxVal<=m[j][i]):
            maxVal = m[j][i]
    maxL.append(maxVal)

for i in minL:
    for j in maxL:
        if i == j:
            ans.append(i)
if ans:
    print(max(ans))
else:
    print('GUESS')


r, c = map(int,input().split())
mat = []
for i in range(r):
    mat.append(list(map(int,input().split())))

flag = 0
for i in range(r):
    min = 10000000000000
    col = []
    for j in range(c):
        if mat[i][j]<min:
            min = mat[i][j]
    for j in range(c):
        if mat[i][j]==min:
           col.append(j)
    for m in col:
     max = 0
     for k in range(r):
        if mat[k][m] > max:
            max = mat[k][m]
     if max == min:
        flag = 1
        print(max)
        break
    if flag == 1:
         break
if flag == 0:
    print('GUESS')


r, c = map(int,input().split())
mat = []
for i in range(r):
    mat.append(list(map(int,input().split())))

flag = 0
for i in range(r):
    min = 10000000000000
    col = []
    for j in range(c):
        if mat[i][j]<min:
            min = mat[i][j]
    for j in range(c):
        if mat[i][j]==min:
           col.append(j)
    for m in col:
     max = 0
     for k in range(r):
        if mat[k][m] > max:
            max = mat[k][m]
     if max == min:
        flag = 1
        print(max)
        break
    if flag == 1:
         break
if flag == 0:
    print('GUESS')