#### Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

## Problem Statement

There are *N* students in 302, all seated in a row. They are numbered in order of their seats, so the leftmost person is 1 and the rightmost is *N*.

There are currently *M* friendships among the students of 302. Each friendship involves two people and is mutual. Two people are considered to *know* each other if they can describe each other as "a friend", "a friend of a friend", or using any such chains of friendships.

Recently, fights have been breaking out in 302. The teacher thinks that it is because people who know each other talk a lot in class, and thus annoy the people in between them who do not know them. Thus, the teacher has ordered the class to make friends with more people such that for any two people *L* and *R* who know each other, everyone in between them must also know them. This will surely return harmony to the class, thought the teacher.

However, different people in 302 don't really get along very well. Thus, they do not like to make friends. Help them find the minimum number of friendships they must form to create the "harmonious class" that the teacher wants.

## Input

The first line of input contains two integers, *N* and *M*.

The next *M* lines of input contain two integers each, *A _{i}* and

*B*, denoting a friendship between the people numbered as such.

_{i}## Output

The first and only line of output should contain a single integer, denoting the minimum number of new friendships that must be formed in 302.

## Limits

For all subtasks, 3 ≤ *N* ≤ 200000 and 1 ≤ *M* ≤ 200000. It is guaranteed that each pair (*A _{i}*,

*B*) only appears once and

_{i}*A*≠

_{i}*B*for all

_{i}*i*.

Subtask 1 (20%): *M* = 1

Subtask 2 (80%): There are no more constraints.

Subtask 3 (0%): Sample test cases.

## Sample Input 1

6 5 1 3 1 4 1 5 1 6 3 6

## Sample Output 1

1

## Sample Input 2

5 3 2 1 3 5 4 5

## Sample Output 2

0

## Explanation

For Sample 1, the class is not harmonious as 2 is in between 1 and 3 (who know each other), but does not know either 1 or 3. However, if 2 makes friends with 4, the class becomes harmonious.

For Sample 2, the class is already harmonious, thus no more friends need to be made.

### Tags

### Subtasks and Limits

Subtask | Score | #TC | Time | Memory | Scoring |
---|---|---|---|---|---|

1 | 20 | 10 | 1s | 256MB | Minimum |

2 | 80 | 22 | 1s | 256MB | Minimum |

3 | 0 | 2 | 1s | 256MB | Minimum |

### Judge Compile Command

g++-7 ans.cpp -o harmony -Wall -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512