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

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

for i in l:

    i[0],i[1]=i[1],i[0]

ll=sorted(l)

x,cnt=ll[0][0],1

for i in ll:

    a=i[1]

    b=i[0]

    if a>=x:

        cnt+=1

        x=b

print(cnt)
from operator import itemgetter



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

l=sorted([list(map(int,input().split())) for i in range(m)],key=itemgetter(1))

x,cnt=l[0][1],1

for i in l:

    a=i[0]

    b=i[1]

    if a>=x:

        cnt+=1

        x=b

print(cnt)
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
for i in l:
    i[0], i[1] = i[1], i[0]
ll = sorted(l)
x, cnt = ll[0][0], 1
for i in ll:
    a = i[1]
    b = i[0]
    if a >= x:
        cnt += 1
        x = b
print(cnt)

from operator import itemgetter

n, m = list(map(int, input().split()))
l = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1))
x, cnt = l[0][1], 1
for i in l:
    a = i[0]
    b = i[1]
    if a >= x:
        cnt += 1
        x = b
print(cnt)

+from operator import itemgetter + -l = [list(map(int, input().split())) for i in range(m)] +l = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1)) +x, cnt = l[0][1], 1 -    i[0], i[1] = i[1], i[0] -ll = sorted(l) -x, cnt = ll[0][0], 1 -for i in ll: -    a = i[1] -    b = i[0] +    a = i[0] +    b = i[1]