问题 G: Friends

内存限制:256 MB 时间限制:3 S
题面:Markdown 评测方式:文本比较 上传者:
提交:6 通过:4

题目描述

There are $\textstyle n$ people standing in a line, numbered from $\textstyle 1$ to $\textstyle n$ from left to right. Among these people, there are $\textstyle m$ pairs of friends. Define an interval $\textstyle [l,r]$ ($\textstyle 1 \leq l \leq r \leq n$) as friendly if and only if every pair of people within the interval are friends. How many friendly intervals are there?

输入格式

The first line contains two integers $\textstyle n$ and $\textstyle m$ ($\textstyle 1 \leq n, m \leq 10^6$), representing the number of people and the number of pairs of friends, respectively. The next $\textstyle m$ lines each contain two integers $\textstyle u$ and $\textstyle v$ ($\textstyle 1 \leq u < v \leq n$), representing a pair of friends. It is guaranteed that there are no duplicate friend pairs in the input.

输出格式

Output a single integer representing the number of friendly intervals.

输入样例 复制

5 9
2 3
1 3
4 5
3 5
1 2
2 4
1 5
1 4
2 5

输出样例 复制

9