def main():

    islands, request_num = list(map(int, input().split()))

    demolition = []

    requests = []

    for _ in range(request_num):

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

    requests.sort(key=lambda x: x[1], reverse=False)

    for begin, end in requests:

        if 0 < len(demolition) and begin <= demolition[-1] < end:

            continue

        else:

            demolition.append(end - 1)

    print((len(demolition)))





if __name__ == '__main__':

    main()



def main():

    n, m = list(map(int, input().split()))

    query = [[int(x) for x in input().split()] for _ in range(m)]

    break_bridges = [-1]

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

    for begin, end in query:

        if not (begin <= break_bridges[-1] < end):

            break_bridges.append(end - 1)

    print((len(break_bridges) - 1))





if __name__ == '__main__':

    main()



def main():
    islands, request_num = list(map(int, input().split()))
    demolition = []
    requests = []
    for _ in range(request_num):
        requests.append(list(map(int, input().split())))
    requests.sort(key=lambda x: x[1], reverse=False)
    for begin, end in requests:
        if 0 < len(demolition) and begin <= demolition[-1] < end:
            continue
        else:
            demolition.append(end - 1)
    print((len(demolition)))


if __name__ == "__main__":
    main()

def main():
    n, m = list(map(int, input().split()))
    query = [[int(x) for x in input().split()] for _ in range(m)]
    break_bridges = [-1]
    query.sort(key=lambda x: x[1])
    for begin, end in query:
        if not (begin <= break_bridges[-1] < end):
            break_bridges.append(end - 1)
    print((len(break_bridges) - 1))


if __name__ == "__main__":
    main()

-    islands, request_num = list(map(int, input().split())) -    demolition = [] -    requests = [] -    for _ in range(request_num): -        requests.append(list(map(int, input().split()))) -    requests.sort(key=lambda x: x[1], reverse=False) -    for begin, end in requests: -        if 0 < len(demolition) and begin <= demolition[-1] < end: -            continue -        else: -            demolition.append(end - 1) -    print((len(demolition))) +    n, m = list(map(int, input().split())) +    query = [[int(x) for x in input().split()] for _ in range(m)] +    break_bridges = [-1] +    query.sort(key=lambda x: x[1]) +    for begin, end in query: +        if not (begin <= break_bridges[-1] < end): +            break_bridges.append(end - 1) +    print((len(break_bridges) - 1))