James loves drinking soup, specifically, magical soup. However, being the connoisseur of soup that he is, he is a picky drinker — meaning that his soup must be up to his standards. In particular, every time he drinks soup, it must satisfy the following conditions:
- The temperature of each bowl of soup must be no more than when he drinks it, or his mouth will get burned. Each bowl of soup starts at some integer temperature and cools down by unit at the end of each minute.
- Each bowl of soup must also be at most minutes old when he drinks it. It isn't fresh enough for him after that.
James starts out with bowls of fresh, new, zero-minute-old soup. Every minute, he can consume at most one bowl of soup. Can you find out the maximum amount of bowls of soup he can drink?
For all subtasks:
Subtask 1 [10%]
Subtask 2 [90%]
No additional constraints.
The first line will contain 2 integers and , representing James' temperature threshold and the number of bowls of soup.
The following lines will each contain two integers and , denoting the starting temperature of each bowl of soup and the amount of time the soup must be consumed in.
Output one integer, the maximum number of bowls of soup James can drink.
Sample Input 1
1 3 3 2 5 1 2 3
Sample Output 1
Explanation for Sample Output 1
James can wait minute to drink the third bowl of soup as the temperature of the soup cools down to . He can wait another minute to drink the first bowl. The second bowl will expire after minute, but the bowl is still too hot so he cannot drink it.
Sample Input 2
20 5 100 91 30 10 69 10 20 1 1 2
Sample Output 2