def main():

    N, M = (int(i) for i in input().split())

    ab = [tuple(int(i) for i in input().split()) for _ in range(M)]

    ab.sort(key=lambda p: p[1])



    pre_b = 1

    ans = 0

    for a, b in ab:

        if pre_b <= a:

            ans += 1

            pre_b = b

    print(ans)





if __name__ == '__main__':

    main()

def main():

    import sys

    input = sys.stdin.buffer.readline

    N, M = (int(i) for i in input().split())

    AB = [[int(i) for i in input().split()] for j in range(M)]

    AB.sort(key=lambda p: p[1])

    mx_b = AB[0][1]

    ans = 1

    for a, b in AB[1:]:

        if a < mx_b:

            continue

        else:

            mx_b = b

            ans += 1

    print(ans)





if __name__ == '__main__':

    main()

def main():
    N, M = (int(i) for i in input().split())
    ab = [tuple(int(i) for i in input().split()) for _ in range(M)]
    ab.sort(key=lambda p: p[1])
    pre_b = 1
    ans = 0
    for a, b in ab:
        if pre_b <= a:
            ans += 1
            pre_b = b
    print(ans)


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(M)]
    AB.sort(key=lambda p: p[1])
    mx_b = AB[0][1]
    ans = 1
    for a, b in AB[1:]:
        if a < mx_b:
            continue
        else:
            mx_b = b
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

+    import sys + +    input = sys.stdin.buffer.readline -    ab = [tuple(int(i) for i in input().split()) for _ in range(M)] -    ab.sort(key=lambda p: p[1]) -    pre_b = 1 -    ans = 0 -    for a, b in ab: -        if pre_b <= a: +    AB = [[int(i) for i in input().split()] for j in range(M)] +    AB.sort(key=lambda p: p[1]) +    mx_b = AB[0][1] +    ans = 1 +    for a, b in AB[1:]: +        if a < mx_b: +            continue +        else: +            mx_b = b -            pre_b = b