I found an interesting problem on https://www.codechef.com/problems/SAD:
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...

I tried it in Python, but could not do it. Can you solve it?
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")