def main():

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

    A = []

    for _ in range(M):

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

        A.append((a,b))



    sort_A = sorted(A)

    left = 0

    right = N

    cnt = 1

    for i in range(M):

        left = max(sort_A[i][0],left)

        right = min(sort_A[i][1], right)

        if left >= right:

            cnt += 1

            right = sort_A[i][1]



    print(cnt)





    







if __name__ == "__main__":

    main()
def main():

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

    X = []

    for _ in range(M):

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

        a -= 1

        b -= 1

        X.append([a,b])

    

    X.sort(key=lambda x: x[1])

    cnt = 1

    now = X[0][1]

    for a, b in X:

        if now <= a:

            cnt += 1

            now = b



    print(cnt)







if __name__ == "__main__":

    main()
def main():
    N, M = list(map(int, input().split()))
    A = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        A.append((a, b))
    sort_A = sorted(A)
    left = 0
    right = N
    cnt = 1
    for i in range(M):
        left = max(sort_A[i][0], left)
        right = min(sort_A[i][1], right)
        if left >= right:
            cnt += 1
            right = sort_A[i][1]
    print(cnt)


if __name__ == "__main__":
    main()

def main():
    N, M = list(map(int, input().split()))
    X = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        X.append([a, b])
    X.sort(key=lambda x: x[1])
    cnt = 1
    now = X[0][1]
    for a, b in X:
        if now <= a:
            cnt += 1
            now = b
    print(cnt)


if __name__ == "__main__":
    main()

-    A = [] +    X = [] -        A.append((a, b)) -    sort_A = sorted(A) -    left = 0 -    right = N +        a -= 1 +        b -= 1 +        X.append([a, b]) +    X.sort(key=lambda x: x[1]) -    for i in range(M): -        left = max(sort_A[i][0], left) -        right = min(sort_A[i][1], right) -        if left >= right: +    now = X[0][1] +    for a, b in X: +        if now <= a: -            right = sort_A[i][1] +            now = b