시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB107770.000%

문제

Every day before Mirko goes to work, he connects to the Internet and reads mail from his boss that contains a list of Mirko's jobs for that day. Each job is defined by its starting time and duration.

Mirko's work shift lasts N minutes. When Mirko arrives to work, he starts processing his jobs. If there are more jobs he has to start working on at the same time, he can choose which one he will process and other jobs are will be processed by his co-workers. When he finishes one job, he read newspapers until next job starts. If Mirko is busy processing one job when another job starts, he will not process that other job not even after he finishes current one.

When more jobs are starting at the same time by choosing which job to process Mirko can increase amount of time he will be free to read newspapers.

Write a program that will help Mirko decide which jobs to process in order to maximize his free time.

입력

First line of the input file contains two integers: N and K, 1 ≤ N ≤ 10000, 1 ≤ K ≤ 10000. N represents how many minutes lasts Mirko's work shift. K represents number of jobs.

Each of the next K lines contains data about one job: integers P and T, meaning that job is starting in Pth minute and its duration is T minutes. 1 ≤ P ≤ N, 1 ≤ P+T-1 ≤ N.

출력

Write to the output file the maximum number of minutes Mirko can spend reading newspapers.

예제 입력 1

10 3
1 2
4 3
5 1

예제 출력 1

5

예제 입력 2

10 6
2 4
2 2
2 1
4 7
8 3
8 1

예제 출력 2

5

예제 입력 3

15 6
1 2
1 6
4 11
8 5
8 1
11 5

예제 출력 3

4