n,m = list(map(int, input().split()))

s = [list(map(int, input().split())) for _ in range(m)]

c = 0

s.sort()

cur = []

for u,v in s:

	if cur == []:

		cur = [u,v]

	if cur[1] <= u:

		cur = [u,v]

		c += 1 

	else:

		cur = [max(u, cur[0]),min(v, cur[1])]

print(c + (1 if cur else 0))

"""

---- ------

     4    9

       ---

       5 6

       ------?

       5 



       5 ----- 10

"""
n,m = list(map(int, input().split()))

s,c = [list(map(int, input().split())) for _ in range(m)], 1

s.sort()

cur = s[0]

for u,v in s[1:]:

	if cur[1] <= u:

		cur,c = [u,v], c + 1 

	else: cur = [max(u, cur[0]),min(v, cur[1])]

print(c)
n, m = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(m)]
c = 0
s.sort()
cur = []
for u, v in s:
    if cur == []:
        cur = [u, v]
    if cur[1] <= u:
        cur = [u, v]
        c += 1
    else:
        cur = [max(u, cur[0]), min(v, cur[1])]
print(c + (1 if cur else 0))
"""
---- ------
     4    9
       ---
       5 6
       ------?
       5 
       5 ----- 10
"""

n, m = list(map(int, input().split()))
s, c = [list(map(int, input().split())) for _ in range(m)], 1
s.sort()
cur = s[0]
for u, v in s[1:]:
    if cur[1] <= u:
        cur, c = [u, v], c + 1
    else:
        cur = [max(u, cur[0]), min(v, cur[1])]
print(c)

-s = [list(map(int, input().split())) for _ in range(m)] -c = 0 +s, c = [list(map(int, input().split())) for _ in range(m)], 1 -cur = [] -for u, v in s: -    if cur == []: -        cur = [u, v] +cur = s[0] +for u, v in s[1:]: -        cur = [u, v] -        c += 1 +        cur, c = [u, v], c + 1 -print(c + (1 if cur else 0)) -""" -     4    9 -       5 6 -       5 -""" +print(c)