#C9915. Laptop Rental Optimization

    ID: 54061 Type: Default 1000ms 256MiB

Laptop Rental Optimization

Laptop Rental Optimization

In this problem, you are given the number of participants in a competition along with details about available laptops in a warehouse. The warehouse inventory is provided as a list of laptop brands and the corresponding count of available laptops for each brand. Your task is to determine the minimum number of laptops that need to be rented so that every participant has a laptop.

Let \( P \) be the number of participants and let the warehouse inventory be represented as a set of pairs \( (b_i, a_i) \) where \( b_i \) is the brand and \( a_i \) is the number of laptops available for that brand. If the total number of available laptops is \( A = \sum_i a_i \), then if \( P \leq A \), no additional laptop rental is needed. Otherwise, you need to rent \( P - A \) laptops.

Note: If the number of participants is negative, treat it as zero (i.e. no laptops are needed).

inputFormat

The input is given from standard input in the following format:

  1. The first line contains an integer \(P\) representing the number of participants.
  2. The second line contains an integer \(N\) representing the number of laptop brands available in the warehouse.
  3. The next \(N\) lines each contain a string and an integer separated by a space. The string represents the laptop brand and the integer represents the number of laptops available for that brand.

It is guaranteed that \(N \geq 0\). If \(N = 0\), then no laptop brand lines will follow.

outputFormat

Output a single integer representing the minimum number of laptops that need to be rented so that every participant gets a laptop. The output should be written to standard output.

## sample
15
3
brandA 5
brandB 6
brandC 2
2