k=int(input())L=[]for _ in range(k): L.append([int(x) for x in input().split()])L.sort(key=lambda x:(x[1],-x[0]))c=0for i in L: if i[1]==-1: c+=1 else:breakprint(max(0,(L[-1][1]-k-c*2)), L[-1][0])