import sys

input = sys.stdin.readline



def main():

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

    ab = sorted([list(map(int, input().split())) for i in range(M)], key = lambda x:x[1])

    count = 0

    break_ = -1

    for a, b in ab:

        a -= 1; b -= 1;

        if a > break_:

            count += 1

            break_ = b-1

    print(count)



if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline



def main():

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

    ab = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x:x[1])



    B = 0

    ans = 0

    for i in range(M):

        a, b = ab[i]

        if a >= B:

            B = b

            ans += 1

    print(ans)



if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    ab = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1])
    count = 0
    break_ = -1
    for a, b in ab:
        a -= 1
        b -= 1
        if a > break_:
            count += 1
            break_ = b - 1
    print(count)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    ab = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1])
    B = 0
    ans = 0
    for i in range(M):
        a, b = ab[i]
        if a >= B:
            B = b
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

-    count = 0 -    break_ = -1 -    for a, b in ab: -        a -= 1 -        b -= 1 -        if a > break_: -            count += 1 -            break_ = b - 1 -    print(count) +    B = 0 +    ans = 0 +    for i in range(M): +        a, b = ab[i] +        if a >= B: +            B = b +            ans += 1 +    print(ans)