# islands war

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

lists=[]

for i in range(m):

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

    lists.append((a,b))

lists=sorted(lists,key=lambda x:(x[0],x[1]))



Uselist=[0 for i in range(n)]

for j in lists:

    if not Uselist[j[0]]:

        Uselist[j[0]]=j

    else:

        continue



uselist=[]

for j in Uselist:

    if j!=0:

        uselist.append(j)

counter=0

inf=0

maxi=10**15

length=len(uselist)

for j in range(length):

    inf=max(inf,uselist[j][0])

    maxi=min(maxi,uselist[j][1])

    if inf<maxi:

        pass

    elif inf>=maxi:

        counter+=1

        inf=maxi

        maxi=uselist[j][1]

print((counter+1))
# atcoder -take a rest-(easy)



def main():

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

    conflict = [tuple(map(int, input().split())) for i in range(M)]

    newest_destroyed = -1

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

    res = 0

    for l, r in conflict:

        if not (l <= newest_destroyed < r):

            res += 1

            newest_destroyed = r-1

    print(res)

    return





if __name__ == "__main__":

    main()





# islands war
n, m = list(map(int, input().split()))
lists = []
for i in range(m):
    a, b = list(map(int, input().split()))
    lists.append((a, b))
lists = sorted(lists, key=lambda x: (x[0], x[1]))
Uselist = [0 for i in range(n)]
for j in lists:
    if not Uselist[j[0]]:
        Uselist[j[0]] = j
    else:
        continue
uselist = []
for j in Uselist:
    if j != 0:
        uselist.append(j)
counter = 0
inf = 0
maxi = 10**15
length = len(uselist)
for j in range(length):
    inf = max(inf, uselist[j][0])
    maxi = min(maxi, uselist[j][1])
    if inf < maxi:
        pass
    elif inf >= maxi:
        counter += 1
        inf = maxi
        maxi = uselist[j][1]
print((counter + 1))

# atcoder -take a rest-(easy)
def main():
    N, M = list(map(int, input().split()))
    conflict = [tuple(map(int, input().split())) for i in range(M)]
    newest_destroyed = -1
    conflict.sort(key=lambda x: x[1])
    res = 0
    for l, r in conflict:
        if not (l <= newest_destroyed < r):
            res += 1
            newest_destroyed = r - 1
    print(res)
    return


if __name__ == "__main__":
    main()

-# islands war -n, m = list(map(int, input().split())) -lists = [] -for i in range(m): -    a, b = list(map(int, input().split())) -    lists.append((a, b)) -lists = sorted(lists, key=lambda x: (x[0], x[1])) -Uselist = [0 for i in range(n)] -for j in lists: -    if not Uselist[j[0]]: -        Uselist[j[0]] = j -    else: -        continue -uselist = [] -for j in Uselist: -    if j != 0: -        uselist.append(j) -counter = 0 -inf = 0 -maxi = 10**15 -length = len(uselist) -for j in range(length): -    inf = max(inf, uselist[j][0]) -    maxi = min(maxi, uselist[j][1]) -    if inf < maxi: -        pass -    elif inf >= maxi: -        counter += 1 -        inf = maxi -        maxi = uselist[j][1] -print((counter + 1)) +# atcoder -take a rest-(easy) +def main(): +    N, M = list(map(int, input().split())) +    conflict = [tuple(map(int, input().split())) for i in range(M)] +    newest_destroyed = -1 +    conflict.sort(key=lambda x: x[1]) +    res = 0 +    for l, r in conflict: +        if not (l <= newest_destroyed < r): +            res += 1 +            newest_destroyed = r - 1 +    print(res) +    return + + +if __name__ == "__main__": +    main()