def main():

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

    y = []

    for i in range(M):

        y.append(list(map(int, input().split())))

    youbou = sorted(y, key = lambda x:x[1])

    

    cnt = 0

    k = 0

    for i in range(M):

        if(youbou[i][0] >= k):

            cnt += 1

            k = youbou[i][1]

    print(cnt)

main()
def main():

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

    island = []

    for i in range(M):

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

        island.append(tuple((a, b)))

    

    s = sorted(island, key=lambda x:x[1])

    

    base = s[0][1]

    cnt = 1

    for i in range(1, len(s)):

        if(s[i][0] >= base):

            base = s[i][1]

            cnt += 1

    print(cnt)

    

main()
def main():
    N, M = list(map(int, input().split()))
    y = []
    for i in range(M):
        y.append(list(map(int, input().split())))
    youbou = sorted(y, key=lambda x: x[1])
    cnt = 0
    k = 0
    for i in range(M):
        if youbou[i][0] >= k:
            cnt += 1
            k = youbou[i][1]
    print(cnt)


main()

def main():
    N, M = list(map(int, input().split()))
    island = []
    for i in range(M):
        a, b = list(map(int, input().split()))
        island.append(tuple((a, b)))
    s = sorted(island, key=lambda x: x[1])
    base = s[0][1]
    cnt = 1
    for i in range(1, len(s)):
        if s[i][0] >= base:
            base = s[i][1]
            cnt += 1
    print(cnt)


main()

-    y = [] +    island = [] -        y.append(list(map(int, input().split()))) -    youbou = sorted(y, key=lambda x: x[1]) -    cnt = 0 -    k = 0 -    for i in range(M): -        if youbou[i][0] >= k: +        a, b = list(map(int, input().split())) +        island.append(tuple((a, b))) +    s = sorted(island, key=lambda x: x[1]) +    base = s[0][1] +    cnt = 1 +    for i in range(1, len(s)): +        if s[i][0] >= base: +            base = s[i][1] -            k = youbou[i][1]