import sys



read = sys.stdin.buffer.read

INF = 1 << 60





def main():

    N, M, *AB = list(map(int, read().split()))



    Q = [[] for _ in range(N - 1)]

    for a, b in zip(*[iter(AB)] * 2):

        Q[a - 1].append(b - 2)



    min_y = INF

    ans = 0

    for i, ys in enumerate(Q):

        if ys:

            min_y = min(min_y, min(ys))

        if i == min_y:

            ans += 1

            min_y = INF



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys

from operator import itemgetter



read = sys.stdin.buffer.read

INF = 1 << 60





def main():

    N, M, *AB = list(map(int, read().split()))



    Q = [0] * M

    for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):

        Q[i] = (a - 1, b - 1)



    Q.sort(key=itemgetter(1))



    ans = 0

    last = -1

    for a, b in Q:

        if last < a:

            last = b - 1

            ans += 1



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read
INF = 1 << 60


def main():
    N, M, *AB = list(map(int, read().split()))
    Q = [[] for _ in range(N - 1)]
    for a, b in zip(*[iter(AB)] * 2):
        Q[a - 1].append(b - 2)
    min_y = INF
    ans = 0
    for i, ys in enumerate(Q):
        if ys:
            min_y = min(min_y, min(ys))
        if i == min_y:
            ans += 1
            min_y = INF
    print(ans)
    return


if __name__ == "__main__":
    main()

import sys
from operator import itemgetter

read = sys.stdin.buffer.read
INF = 1 << 60


def main():
    N, M, *AB = list(map(int, read().split()))
    Q = [0] * M
    for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
        Q[i] = (a - 1, b - 1)
    Q.sort(key=itemgetter(1))
    ans = 0
    last = -1
    for a, b in Q:
        if last < a:
            last = b - 1
            ans += 1
    print(ans)
    return


if __name__ == "__main__":
    main()

+from operator import itemgetter -    Q = [[] for _ in range(N - 1)] -    for a, b in zip(*[iter(AB)] * 2): -        Q[a - 1].append(b - 2) -    min_y = INF +    Q = [0] * M +    for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)): +        Q[i] = (a - 1, b - 1) +    Q.sort(key=itemgetter(1)) -    for i, ys in enumerate(Q): -        if ys: -            min_y = min(min_y, min(ys)) -        if i == min_y: +    last = -1 +    for a, b in Q: +        if last < a: +            last = b - 1 -            min_y = INF