parity-game-icpc-11

There are N boxes numbered from 1 to N arranged in a line. A single box may or may not have a candy inside. You decided to play the following game with your friend Marcus:

Marcus asks you Q questions. In a single question, he can ask about the parity of candies in boxes in some range [a, b] and you have to provide him the correct answer. Marcus wins, as soon as he has the required knowledge to point out all boxes with candies inside them without making any mistakes.

You are given a list of consecutive questions asked by Marcus. Your task is to decide, what is the minimum number of questions, which you can erase from Marcus list, in order to make the game impossible to be finished.

Constraints:

1 ≤ N ≤ 400
1 ≤ Q ≤ 60000
1 ≤ a ≤ b ≤ N

Input format:

In the first line, there are two integers N and Q, denoting the number of boxes and the number of questions asked by Marcus.
Q lines follow, in the i-th of them, there are two integers a and b, denoting two endpoints of a range corresponding to the i-th question asked by Marcus

Output format:

In one line, output single integer denoting the answer to the problem.

SAMPLE INPUT
3 3
1 2
2 3
3 3

SAMPLE OUTPUT
1

Explanation

Marcus asked about parity of 3 ranges. When you erase his last question, he won't able to decide if the last box contains a candy or not

Source: hackerearth | Difficulty: HARD
Tags: Graph algorithms


Solutions: