m = input()
y = []
result = []
dic = dict()
def predict(y,seita):
if y < seita:
return 0
else:
return 1
def getkey(dic,maxvalue):
dic = dict(dic)
indexs = []
for key,value in dic.items():
if value == maxvalue:
indexs.append(key)
return max(indexs)
for i in range(int(m)):
y_,result_ = input().split()
y_ = int(y_)
result_ = int(result_)
y.append(y_)
result.append(result_)
if y_<0 or y_>10**8:
pass
for seita in y:
count = 0
for index,yi in enumerate(y):
if predict(yi,seita) == result[index]:
count = count + 1
dic[seita] = count
print(getkey(dic,max(dic.values())))