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

islands = [tuple(map(int, input().split())) for _ in range(M)]

islands.sort()



cnt = 0

l = 1

r = N

for left, right in islands:

    if r <= left:

        cnt += 1

        l = left

        r = right

    else:

        l = max(l, left)

        r = min(r, right)



print((cnt+1))
from operator import itemgetter



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

ab = [tuple(map(int, input().split())) for _ in range(M)]

ab.sort(key=itemgetter(1))

east_island = ab[0][1]

answer = 1



for i, j in ab:

    if i >= east_island:

        answer += 1

        east_island = j



print(answer)

N, M = list(map(int, input().split()))
islands = [tuple(map(int, input().split())) for _ in range(M)]
islands.sort()
cnt = 0
l = 1
r = N
for left, right in islands:
    if r <= left:
        cnt += 1
        l = left
        r = right
    else:
        l = max(l, left)
        r = min(r, right)
print((cnt + 1))

from operator import itemgetter

N, M = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(M)]
ab.sort(key=itemgetter(1))
east_island = ab[0][1]
answer = 1
for i, j in ab:
    if i >= east_island:
        answer += 1
        east_island = j
print(answer)

+from operator import itemgetter + -islands = [tuple(map(int, input().split())) for _ in range(M)] -islands.sort() -cnt = 0 -l = 1 -r = N -for left, right in islands: -    if r <= left: -        cnt += 1 -        l = left -        r = right -    else: -        l = max(l, left) -        r = min(r, right) -print((cnt + 1)) +ab = [tuple(map(int, input().split())) for _ in range(M)] +ab.sort(key=itemgetter(1)) +east_island = ab[0][1] +answer = 1 +for i, j in ab: +    if i >= east_island: +        answer += 1 +        east_island = j +print(answer)