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

AB=[]

for _ in range(M):

    a,b=[int(x)-1 for x in input().split()]

    AB.append((a,b,b*10**6+a))

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

ans=0

i=0

k=0

while i<N-1 and k<M:

    a,b,c=AB[k]

    i=b-1

    ans+=1

    j=k+1

    while j<M:

        a,b,c=AB[j]

        if i<a: break

        j+=1

    k=j

print(ans)
import sys

def main():

    input = sys.stdin.readline

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

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

    from operator import itemgetter

    AB.sort(key=itemgetter(1))

    ans=0

    last=-1

    for a,b in AB:

        if last<=a:

            ans+=1

            last=b

    print(ans)



if __name__ == '__main__':

    main()
N, M = list(map(int, input().split()))
AB = []
for _ in range(M):
    a, b = [int(x) - 1 for x in input().split()]
    AB.append((a, b, b * 10**6 + a))
AB.sort(key=lambda x: x[2])
ans = 0
i = 0
k = 0
while i < N - 1 and k < M:
    a, b, c = AB[k]
    i = b - 1
    ans += 1
    j = k + 1
    while j < M:
        a, b, c = AB[j]
        if i < a:
            break
        j += 1
    k = j
print(ans)

import sys


def main():
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    AB = [tuple(map(int, input().split())) for _ in range(M)]
    from operator import itemgetter

    AB.sort(key=itemgetter(1))
    ans = 0
    last = -1
    for a, b in AB:
        if last <= a:
            ans += 1
            last = b
    print(ans)


if __name__ == "__main__":
    main()

-N, M = list(map(int, input().split())) -AB = [] -for _ in range(M): -    a, b = [int(x) - 1 for x in input().split()] -    AB.append((a, b, b * 10**6 + a)) -AB.sort(key=lambda x: x[2]) -ans = 0 -i = 0 -k = 0 -while i < N - 1 and k < M: -    a, b, c = AB[k] -    i = b - 1 -    ans += 1 -    j = k + 1 -    while j < M: -        a, b, c = AB[j] -        if i < a: -            break -        j += 1 -    k = j -print(ans) +import sys + + +def main(): +    input = sys.stdin.readline +    N, M = list(map(int, input().split())) +    AB = [tuple(map(int, input().split())) for _ in range(M)] +    from operator import itemgetter + +    AB.sort(key=itemgetter(1)) +    ans = 0 +    last = -1 +    for a, b in AB: +        if last <= a: +            ans += 1 +            last = b +    print(ans) + + +if __name__ == "__main__": +    main()