#P2207. [USACO13OPEN] Photo B

[USACO13OPEN] Photo B

Description

Farmer John plans to photograph his nn cows. They stand in a line and are numbered 1n1\sim n in order.

Each photo can include a contiguous interval of cows in the line. For every cow, FJ wants it to appear in at least one photo.

Unfortunately, there are kk pairs of cows that do not get along; they refuse to appear in the same photo. Given the positions of all incompatible pairs, compute the minimum number of photos FJ needs to take.

Input Format

The first line contains two integers n,kn, k.

Lines 2k+12\sim k+1: on line i+1i+1, there are two integers aia_i and bib_i, indicating that the cow at position aia_i and the cow at position bib_i are an incompatible pair.

Output Format

Output a single integer, the minimum number of photos FJ needs.

7 3
1 3
2 4
5 6

3

Hint

Sample 1 explanation: FJ can take only three photos: [1,2],[3,5],[6,7][1,2],[3,5],[6,7].

Constraints: For 100%100\% of the testdata, it is guaranteed that 2n1092\le n\le 10^9, 1k10001\le k\le 1000, 1ai,bin1\le a_i, b_i\le n.

Translated by ChatGPT 5