ICPC PACNW 2016 H - Paint

View as PDF

Submit solution


Points: 7
Time limit: 1.8s
Memory limit: 256M

Problem type

You are painting a fence with n sections, numbered from 1 to n. There are k artists, each willing to paint their design on a specific portion of the fence. However, artists will never agree to have their section painted over, so they will only paint their portion of the fence if no one else will paint any part of it.

You want to select a set of painters that does not conflict to minimize the number of unpainted sections.

Input

The first line contains two positive integers n (1n1018) and k (1k200000).

Each of the next k lines contains two positive integers ai and bi, where 1aibin, indicating that the ith artist wants to paint all sections between section ai and section bi, inclusive.

Output

Print, on a single line, a single integer indicating the minimum number of unpainted sections.

Sample Input

Copy
8 3
1 3
2 6
5 8

Sample Output

Copy
1
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments

There are no comments at the moment.