Codeforces Round 351 (VK Cup 2016 Round 3, Div. 2 Edition)
B
Problems for Round
Codeforces
1300
原题
← AC →
翻译中…

There are $*n*$ problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are $*m*$ pairs of similar problems. Authors want to split problems between two division according to the following rules:

翻译中…
  • Problemset of each division should be non-empty.
  • Each problem should be used in exactly one division (yes, it is unusual requirement).
  • Each problem used in division 1 should be harder than any problem used in division 2.
  • If two problems are similar, they should be used in different divisions.
翻译中…

Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other.

翻译中…

Note, that the relation of similarity is not transitive. That is, if problem $*i*$ is similar to problem $*j*$ and problem $*j*$ is similar to problem $*k*$, it doesn't follow that $*i*$ is similar to $*k*$.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($2 ≤ *n* ≤ 100 000$, $0 ≤ *m* ≤ 100 000$) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.

翻译中…

Each of the following $*m*$ lines contains a pair of similar problems $*u*_{*i*}$ and $*v*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*, *u*_{*i*} ≠ *v*_{*i*}$). It's guaranteed, that no pair of problems meets twice in the input.

翻译中…

Output

翻译中…

Print one integer — the number of ways to split problems in two divisions.

翻译中…

Note

翻译中…

In the first sample, problems $1$ and $2$ should be used in division 2, while problems $4$ and $5$ in division 1. Problem $3$ may be used either in division 1 or in division 2.

翻译中…

In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.

翻译中…

Third sample reminds you that the similarity relation is not transitive. Problem $3$ is similar to both $1$ and $2$, but $1$ is not similar to $2$, so they may be used together.

翻译中…

样例

Input #1
5 2
1 4
5 2
Output #1
2
InputCopy OutputCopy
Input #2
3 3
1 2
2 3
1 3
Output #2
0
InputCopy OutputCopy
Input #3
3 2
3 1
3 2
Output #3
1
InputCopy OutputCopy
题目信息
题号
673B
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。