St Andrews Online Judge

Book Piano Room

By Kay Akashi

Time: 1000 ms
Memory: 256000 kB

The code judging system is only available during contests. Check out the github repo for test cases and solutions.

Loading account information...

Problem Statement

In the Music Centre, there is only one piano practice room. There are nn time slots in a single day available for the piano practice room.

One person is permitted to book several time slots in a day. The rule for booking is that, one firstly chooses consecutive time slots, and he/she can use practice rooms during those time slots where there's no preexisting booking.

Students and teaching staff love playing the piano, and today mm people are trying to book piano rooms. It is known that ii-th person (1im)(1 \leq i \leq m) would like to book a room between lil_{i}-th time slot and rir_{i}-th time slot inclusive.

Your task is to output the number of time slots in which the practice room is vacant.

Note that, ii-th person can make bookings earlier than (i+1)(i + 1)-th person does (1in1)(1 \leq i \leq n - 1).

Constraints

1n,m1051 \leq n, m \leq 10^{5}, 1lrn1 \leq l \leq r \leq n.

Subtask 1 (20%)

1n,m<1001 \leq n, m \lt 100.

Subtask 2 (80%)

100n,m105100 \leq n, m \leq 10^{5}.

Input

The first line of input contains two integers, nn and mm. Following are mm lines ii-th of which contains two integers lil_{i} and rir_{i}.

Output

Output the answer.

Examples

Input

5 2
1 2
4 5

Output

1

Explanation

Time slots 11 and 22 are booked by the first person. Time slots 44 and 55 are booked by the second person. The only remaining vacant time slot is the time slot 33, so the answer is 11.

Input

6 3
1 4
2 5
6 6

Output

0

Explanation

Time slots 11, 22, 33, and 44 are booked by the first person. Time slot 55 is booked by the second person. Time slot 66 is booked by the third person. Because there's no single time slot available for pianists, the answer is 00.