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

table=[]

for i in range(M):

    a,b=list(map(int,input().split()))

    table.append((a-1,b-2))

table.sort()

s=0

t=N

ans=0

for a,b in table:

    if t<a:

        ans+=1

        s=a

        t=b

    else:

        s=a

        t=min(t,b)

        #print(s,t)

print((ans+1))

    
from operator import itemgetter

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

table=[]

for i in range(M):

    a,b=list(map(int,input().split()))

    table.append((a,b))

table=sorted(table, key=itemgetter(1))

ans=0

t=0

for a,b in table:

    if t<a:

        ans+=1

        t=b-1

print(ans)
N, M = list(map(int, input().split()))
table = []
for i in range(M):
    a, b = list(map(int, input().split()))
    table.append((a - 1, b - 2))
table.sort()
s = 0
t = N
ans = 0
for a, b in table:
    if t < a:
        ans += 1
        s = a
        t = b
    else:
        s = a
        t = min(t, b)
        # print(s,t)
print((ans + 1))

from operator import itemgetter

N, M = list(map(int, input().split()))
table = []
for i in range(M):
    a, b = list(map(int, input().split()))
    table.append((a, b))
table = sorted(table, key=itemgetter(1))
ans = 0
t = 0
for a, b in table:
    if t < a:
        ans += 1
        t = b - 1
print(ans)

+from operator import itemgetter + -    table.append((a - 1, b - 2)) -table.sort() -s = 0 -t = N +    table.append((a, b)) +table = sorted(table, key=itemgetter(1)) +t = 0 -        s = a -        t = b -    else: -        s = a -        t = min(t, b) -        # print(s,t) -print((ans + 1)) +        t = b - 1 +print(ans)