#K60937. Find the Winning Team

    ID: 31197 Type: Default 1000ms 256MiB

Find the Winning Team

Find the Winning Team

You are given a competition with k teams, numbered from 1 to k, and n tasks. Each task assigns points to a team. The goal is to determine the team with the highest total points. If several teams are tied for the highest points, you must choose the team with the smallest team id.

The total points for team i is defined as

Si=j=1npijS_i = \sum_{j=1}^{n} p_{ij}

where \(p_{ij}\) is the points awarded to team i for the jth task (if any). In the case of no tasks (n = 0), assume every team's score is 0 and therefore the winning team is team 1 by default.

Your task is to implement a program that reads the input from standard input (stdin) and prints the result to standard output (stdout).

inputFormat

The input consists of:

  • The first line contains two integers k and n, representing the number of teams and the number of tasks respectively.
  • The following n lines each contain two integers: team_id and points, indicating that the team with the given id earned the specified points for a task.

outputFormat

Output a single integer, the id of the winning team (printed to stdout), determined by the highest total points. In case of a tie, output the smallest team id among those tied.

## sample
3 4
1 10
2 20
3 15
2 10
2

</p>