#P1932F. Feed Cats

    ID: 10411 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>data structuresdpsortings*1900

Feed Cats

Description

There is a fun game where you need to feed cats that come and go. The level of the game consists of nn steps. There are mm cats; the cat ii is present in steps from lil_i to rir_i, inclusive. In each step, you can feed all the cats that are currently present or do nothing.

If you feed the same cat more than once, it will overeat, and you will immediately lose the game. Your goal is to feed as many cats as possible without causing any cat to overeat.

Find the maximum number of cats you can feed.

Formally, you need to select several integer points from the segment from 11 to nn in such a way that among given segments, none covers two or more of the selected points, and as many segments as possible cover one of the selected points.

The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains two integers nn and mm (1n1061 \le n \le 10^6, 1m21051 \le m\le 2\cdot 10^5).

The ii-th of the next mm lines contains a pair of integers lil_i and rir_i (1lirin1 \le l_i \le r_i \le n).

The sum of nn for all tests does not exceed 10610^6, the sum of mm for all tests does not exceed 21052\cdot 10^5.

For each test case, print a single integer, the maximum number of cats you can feed.

Input

The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains two integers nn and mm (1n1061 \le n \le 10^6, 1m21051 \le m\le 2\cdot 10^5).

The ii-th of the next mm lines contains a pair of integers lil_i and rir_i (1lirin1 \le l_i \le r_i \le n).

The sum of nn for all tests does not exceed 10610^6, the sum of mm for all tests does not exceed 21052\cdot 10^5.

Output

For each test case, print a single integer, the maximum number of cats you can feed.

Sample Input 1

3
15 6
2 10
3 5
2 4
7 7
8 12
11 11
1000 1
1 1000
5 10
1 2
3 4
3 4
3 4
3 4
1 1
1 2
3 3
3 4
3 4

Sample Output 1

5
1
10

Note

In the first example, one of the ways to feed five cats is to feed at steps 44 and 1111.

  • At step 44, cats 11, 22, and 33 will be fed.
  • At step 1111, cats 55 and 66 will be fed.