new_contents: """
  if __name__ == '__main__':
  
      for _ in range(int(input())):
          name = input()
          score = float(input())
  """
  # pythonNestedLists.py
  #!/usr/bin/env python
  
  N = int(input())
  
  students = list()
  for i in range(N):
      students.append([input(), float(input())])
  
  scores = set([students[x][1] for x in range(N)])
  scores = list(scores)
  scores.sort()
  
  students = [x[0] for x in students if x[1] == scores[1]]
  students.sort()
  
  for s in students:
      print (s)
  
subject: Create HR_pythonNestedLists.py