시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB278829.630%

문제

You are given a graph with n vertices and m undirected edges. The vertices are numbered from 1 to n. We number the edges in the order of their appearance in the input, starting with 1. Let for each pair of numbers of edges (i, j) for which 1 ≤ i ≤ j ≤ m, create a new graph with edges that are the edges of the original graph with numbers from i to j inclusive and for the vertices of the new graph we take all vertices of the original graph. Write program connect that finds how many of these newly created graphs are connected.

입력

The first line of the standard input contains the values of n and m. It follows m lines in the input, each containing two integers: u and v, specifying the vertices of the corresponding edge in the original graph.

출력

Your program should print on the standard output one integer equal to the count of newly created connected graphs.

제한

  • 2 ≤ n ≤ 50 000
  • 1 ≤ m ≤ 200 000
  • 1 ≤ u ≤ n
  • 1 ≤ v ≤ n
  • The graph may contain multi-edges and loops.

서브태스크

번호배점제한
15

n ≤ 100; m ≤ 200

215

n ≤ 2 000; m ≤ 5 000

340

n ≤ 200

440

No additional constrains

예제 입력 1

4 4
1 2
2 4
1 3
1 4

예제 출력 1

3

힌트

The pairs of edges (i, j) for which the corresponding new graph is connected are (1, 3), (1,4) and (2,4). More precisely:

  • (1,3) – this includes edges with numbers 1, 2 and 3;
  • (1,4) – this includes edges with numbers 1, 2, 3 and 4;
  • (2,4) – this includes edges with numbers 2, 3 and 4.

채점 및 기타 정보

  • 예제는 채점하지 않는다.