Special Number Finding from a 2-D Matrix

I have submitted a code for a problem whose link is:

My submission fails due to wrong answer. Can someone help me figure out what’s wrong with my code? My code submission is as follows:

cook your dish here

nestedList = []
matrixList = []
ansSet = set()
m = 0

while True:
try:
nestedList = input().split(’ ')
n = len(nestedList)
m += 1
ansSet.add(min(nestedList))
ansSet.add(max(nestedList))
matrixList.append(nestedList[:])
nestedList.clear()
except:
break

for i in range(0, n):
for j in range(0, m):
nestedList.append(matrixList[j][i])
ansSet.add(min(nestedList))
ansSet.add(max(nestedList))
nestedList.clear()

print(len(ansSet))