N, M = list(map(int,input().split()))

E = sorted([list(map(int, input().split())) for _ in range(M)])



c = E[0]

cnt = 0

for i in range(1,M):

	if c[0] <= E[i][0] < c[1]:

		c = [max(c[0],E[i][0]), min(c[1],E[i][1])]

	else:

		cnt += 1

		c = E[i]



print((cnt+1))
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

 

from operator import itemgetter

 

N,M = list(map(int,readline().split()))

m = list(map(int,read().split()))

AB = sorted(zip(m,m))

AB.sort(key = lambda x: x[1])





c = AB[0][1]

ans = 1

for i in range(1,M):

	if AB[i][0] < c:

		continue

	else:

		ans += 1

		c = AB[i][1]



print(ans)
N, M = list(map(int, input().split()))
E = sorted([list(map(int, input().split())) for _ in range(M)])
c = E[0]
cnt = 0
for i in range(1, M):
    if c[0] <= E[i][0] < c[1]:
        c = [max(c[0], E[i][0]), min(c[1], E[i][1])]
    else:
        cnt += 1
        c = E[i]
print((cnt + 1))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter

N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
AB = sorted(zip(m, m))
AB.sort(key=lambda x: x[1])
c = AB[0][1]
ans = 1
for i in range(1, M):
    if AB[i][0] < c:
        continue
    else:
        ans += 1
        c = AB[i][1]
print(ans)

-N, M = list(map(int, input().split())) -E = sorted([list(map(int, input().split())) for _ in range(M)]) -c = E[0] -cnt = 0 +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +from operator import itemgetter + +N, M = list(map(int, readline().split())) +m = list(map(int, read().split())) +AB = sorted(zip(m, m)) +AB.sort(key=lambda x: x[1]) +c = AB[0][1] +ans = 1 -    if c[0] <= E[i][0] < c[1]: -        c = [max(c[0], E[i][0]), min(c[1], E[i][1])] +    if AB[i][0] < c: +        continue -        cnt += 1 -        c = E[i] -print((cnt + 1)) +        ans += 1 +        c = AB[i][1] +print(ans)