CodeEff/ECCO huggingface dataset:
# Original solution
from copy import copy
from collections import deque

N,M=list(map(int,input().split()))
ab=[]
for i in range(M):
    a,b=list(map(int,input().split()))
    ab.append([a,b])

"""
N=10**5
M=10**5
ab=[]
for i in range(1,N):
    ab.append([i,i+1])
"""
AB=copy(ab)
ab.sort(key=lambda x :x[1])
AB.sort()
ab=deque(ab)
AB=deque(AB)
num=0
while(ab):
    p=ab.popleft()
    AB.remove(p)
    num+=1
    e=p[1]
    Q=copy(AB)
    for I in AB:
        if I[0]<e:
            Q.remove(I)
            ab.remove(I)
        else:
            break
    AB=Q
print(num)

# Optimized solution
from collections import deque
N,M=list(map(int,input().split()))
ab=[]
for i in range(M):
    a,b=list(map(int,input().split()))
    ab.append([a,b])

ab.sort(key=lambda x :x[1])
ans=deque()
for i in ab:
    if len(ans)>0:
        if i[0]<ans[-1] :
            continue
    ans.append(i[1])
print((len(ans)))
# Original solution
from collections import deque
N,M=list(map(int,input().split()))
ab=[]
for i in range(M):
    a,b=list(map(int,input().split()))
    ab.append([a,b])

ab.sort(key=lambda x :x[1])
ans=deque()
for i in ab:
    if len(ans)>0:
        if i[0]<ans[-1] :
            continue
    ans.append(i[1])
print((len(ans)))

# Optimized solution
N,M=list(map(int,input().split()))
ab=[]
for i in range(M):
    a,b=list(map(int,input().split()))
    a,b=a-1,b-2
    ab.append([a,b])
ab.sort(key=lambda x:x[1])
ans=1
x=ab[0][1]
for a,b in ab[1:]:
    if a<=x:
        continue
    x=b
    ans+=1
print(ans)
# Original solution
N,M=list(map(int,input().split()))
Y=[list(map(int,input().split())) for i in range(M)]
Y.sort(key=lambda x:x[1])
K=1
x=Y[0][1]
for a,b in Y[1:]:
    if a+1>x:
        x=b
        K+=1
print(K)


# Optimized solution
N,M=list(map(int,input().split()))
T=[]
for i in range(M):
    u,v=list(map(int,input().split()))
    u,v=u,v-1
    T.append([u,v])
T.sort(key=lambda x:x[1])
tmp=0
ans=0
for i in range(M):
    if tmp<T[i][0]:
        tmp=T[i][1]
        ans+=1
print(ans)
# Original solution
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
ab = sorted(ab, key=lambda x:x[1], reverse=True)

dellist = lambda items,indices: [item for idx,item in enumerate(items) if idx not in indices]

count = 0
while len(ab) != 0:
  p = ab.pop()
  count += 1
  del_idx = []
  for i in range(len(ab)):
    if ab[i][0] < p[1]:
      del_idx.append(i)
  ab = dellist(ab, del_idx) # ['japanese','!!']
print(count)

# Optimized solution
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
ab = sorted(ab, key=lambda x:x[1])
count = 0

del_num = 0
for i in range(M):
  if ab[i][0] >= del_num:
    count += 1
    del_num = ab[i][1]
print(count)
# Original solution

N, M = list(map(int, input().split()))
bridge = [ list(map(int, input().split())) for _ in range(M)]

cut_count = 0
while True:
    summ = [ 0 for _ in range(N)]
    for b in bridge:
        for i in range(N):
            if (b[0] - 1) <= i < (b[1] - 1):
                summ[i] += 1
#     print(summ, bridge)
    maxx = max(summ)
    if maxx < 2:
        print((str(len(bridge) + cut_count)))
        break
    else:
        cut_count += 1
        ind = summ.index(maxx)
        new_bridge = []
        for b in bridge:
            for i in range(N):
                if (b[0] - 1) <= ind < (b[1] - 1):
                    pass
                else:
                    new_bridge.append(b)
                    break
        bridge = new_bridge
        

# Optimized solution

N, M = list(map(int, input().split()))
bridge = [ list(map(int, input().split())) for _ in range(M)]

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

cuts = [bridge[0][1]]
for b in bridge[1:]:
    cut = cuts[-1]
    if b[0]< cut <= b[1]:
        continue
    cuts.append(b[1])

# print(cuts)
print((len(cuts)))
# Original solution
# ABC103 D-Islands War

N, M = list(map(int, input().split()))
ab = []
for i in range(M):
    ab.append(list(map(int, input().split())))
    
ab = sorted(ab, key=lambda x:x[1])
ans = 0
lastremoved = 0

for i, j in enumerate(ab):
    if i == 0:
        ans += 1
        temp = j[1] - 1
    else:
        if j[0] <= temp:
            continue
        else:
            ans += 1
            temp = j[1] - 1
            
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
box = [list(map(int, input().split())) for _ in range(M)]
box = sorted(box, key= lambda x: x[1])
rmax = box[0][1]
ans = 1
for i in range(1, M):
    if box[i][0] >= rmax:
        rmax = box[i][1]
        ans += 1
    else:
        continue
print(ans)
# Original solution
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged
N,M = list(map(int,input().split(" ")))
isbr = []
for i in range(M):
  isbr.append(list(map(int,input().split(" "))))
isbr = merge_sort(isbr)
rem = []
i = 0
while i < M:
  a = isbr[i][0]
  b = isbr[i][1]
  flag = 0
  while a <= b:
    if b in rem:
      flag = 1
      break
    else:
      b-=1
  if flag == 0:
    rem.append(isbr[i][1]-1)
  i+=1
print((len(rem)))

# Optimized solution
#D問題
N,M=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(M)]
AB=sorted(AB, key=lambda x: x[1])
bridges=[]
for i in range(M):
    if len(bridges) == 0:
        bridges.append(AB[i][1]-1)
    elif max(bridges)>=AB[i][0]:
        pass
    else:
        bridges.append(AB[i][1]-1)
print((len(bridges)))
# Original solution
n,m=[int(x) for x in input().split()]
ab=[[int(x) for x in input().split()] for i in range(m)]

ab.sort(key=lambda x:x[1])
#print(ab)
split=[0,]

while len(ab)!=0:
  if ab[0][1]-split[-1]>0 and ab[0][0]-split[-1]<=0:
    ab.pop(0)
  else:
    split.append(ab[0][1]-1)
  
  #print(ab)
print((len(split)-1))

# Optimized solution
n,m=[int(x) for x in input().split()]
ab=[[int(x) for x in input().split()] for i in range(m)]

ab.sort(key=lambda x:x[1])
#print(ab)
split=[0,]

#while len(ab)!=0:
for item in ab:
  if (item[1]-split[-1]>0 and item[0]-split[-1]<=0)!=True:
    split.append(item[1]-1)
  
  #print(ab)
print((len(split)-1))
# Original solution
N,M = list(map(int,input().split()))
ab = []
dp = [0 for i in range(N)]
for i in range(M):
    a,b = list(map(int,input().split()))
    ab.append([a-1,b-1])
ab.sort(key = lambda ab:ab[1])
count = 0
while ab:
    a,b = ab.pop(0)
    for i in range(len(ab)-1,-1,-1):
        if ab[i][0] < b:
            ab.remove(ab[i])
    count += 1
print(count)

# Optimized solution
N,M = list(map(int,input().split()))
ab = []
for i in range(M):
    ab.append(list(map(int,input().split())))
ab.sort(key = lambda ab:ab[1])
count = 0
now = 0
for a,b in ab:
    if a >= now:
        count += 1
        now = b
print(count)
# Original solution
n,m = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(m)]
l.sort(key=lambda x:x[1],reverse = True)
dec = 0
while l:
  a = l.pop()
  dec += 1
  l = [i for i in l if not (i[0] < a[1] <= i[1])]
print(dec)

# Optimized solution
n,m = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(m)]
l.sort(key=lambda x:x[1])
dec = 0
cur = 0
for i in l:
  if i[0] < cur <= i[1]:
    continue
  else:
    dec += 1
    cur = i[1]
print(dec)
# Original solution
n,m=list(map(int,input().split()))
ab=[[0]*2 for _ in range(m)]
for i in range(m):
  ab[i][1],ab[i][0]=list(map(int,input().split()))
ab.sort()
cnt=0
num=0
for i in range(m):
  if ab[i][1]<=num:
    continue
  else:
    cnt+=1
    num=ab[i][0]-1
print(cnt)

# Optimized solution
n,m=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(m)]
ab.sort(key=lambda x:x[1])
cnt=0
x=-1
for i in range(m):
  if x<ab[i][0]:
    x=ab[i][1]-1
    cnt+=1
print(cnt)
# Original solution
N,M = list(map(int,input().split()))
a = [0 for i in range(M)]
b = [0 for i in range(M)]
for i in range(M):
    A,B = list(map(int,input().split()))
    a[i] = A
    b[i] = B

ans = 0
while 1:
    if len(a) == 0:
        break
    maxVal = max(a)
    maxIdx = a.index(maxVal)

    for j in reversed(list(range(len(a)))):
        if a[j] <= maxVal <= b[j] - 1:
            a.pop(j)
            b.pop(j)

    ans += 1

print(ans)

# Optimized solution
N,M = list(map(int,input().split()))
listAB = [list([int(x) for x in input().split()]) for i in range(M)]
# 要素の2番目でソート
listAB.sort(key=lambda x: x[1])
# 最後に切った橋の位置
last = -1
ans = 0
for a,b in listAB:
    # 切った橋より右側に依頼があるか
    if last <= a:
        ans += 1
        # 切った位置はbの位置
        last = b

print(ans)
# Original solution
n,m = list(map(int, input().split()))
qp = [tuple(map(int, input().split())) for _ in range(m)]

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

ans = 0
pre = 0

while qp:
    a,b = qp.pop(0)
    if pre<a:
        ans += 1
        pre = b-1
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

n,m = list(map(int, input().split()))
qp = [tuple(map(int, input().split())) for _ in range(m)]

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

ans = 0
pre = 0

while qp:
    a,b = qp.pop(0)
    if pre<a:
        ans += 1
        pre = b-1
print(ans)
# Original solution
N,M=list(map(int, input().split()))
G=[list() for i in range(N)]
for i in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
ans=0
index=-1
for i in range(1,N):
    for p in G[i]:
        if index<p<i:
            ans+=1
            index=i-1
import time
time.sleep(1.54)
print(ans)


# Optimized solution
N,M=list(map(int, input().split()))
G=[list() for i in range(N)]
for i in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
ans=0
index=-1
for i in range(1,N):
    for p in G[i]:
        if index<p<i:
            ans+=1
            index=i-1
print(ans)
# Original solution
N,M=list(map(int, input().split()))
G=[list() for i in range(N)]
for i in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
ans=0
index=-1
for i in range(1,N):
    for p in G[i]:
        if index<p<i:
            ans+=1
            index=i-1
import time
time.sleep(1.54)
print(ans)


# Optimized solution
N,M=list(map(int, input().split()))
G=[list() for i in range(N)]
for i in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
ans=0
index=-1
for i in range(1,N):
    for p in G[i]:
        if index<p<i:
            ans+=1
            index=i-1
            break
print(ans)
# Original solution
from functools import reduce
from operator import itemgetter

N, M = list(map(int, input().split()))
a, b = list(zip(*(list(map(int, input().split())) for _ in range(M))))
ts = sorted(zip(a, b), key=itemgetter(1))
ans = reduce(
    lambda acc, t: acc if t[0] < acc[1] else (acc[0] + 1, t[1]),
    ts,
    (0, 0)
)[0]
print(ans)


# Optimized solution
from functools import reduce
from operator import itemgetter

N, M = list(map(int, input().split()))
a, b = (
    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else
    ((), ())
)

# bについてソートし、橋を取り除く必要があれば可能な限り東の橋を取り除く
ans, _ = reduce(
    lambda acc, q: (
        (acc[0] + 1, q[1]) if q[0] >= acc[1] else
        acc
    ),
    sorted(zip(a, b), key=itemgetter(1)),
    (0, 0)
)

print(ans)
# Original solution
a=list(map(int,input().split()))
b=[]
c=[1]*(a[0]-1)
for i in range(a[1]):
  b.append(list(map(int,input().split())))
b=sorted(b,key=lambda b:b[1])
for i in range(a[1]):
  if i!=0 and b[i-1][0]>=b[i][0]:
    continue
  if 0 in c[(b[i][0]-1):b[i][1]]:
    continue
  else:
    c[(b[i][1])-2]=0

print((c.count(0)))

# Optimized solution
a=list(map(int,input().split()))
b=[]
c=0
r=0
for i in range(a[1]):
  b.append(list(map(int,input().split())))
b=sorted(b,key=lambda b:b[1])

for i in range(a[1]):
  if b[i][0]<=r:
    continue
  else:
    c=c+1
    r=b[i][1]-1

print(c)
# Original solution
n,m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(m)]
b = []
for i in range(len(a)):
    c = a[i]
    d = list(range(c[0], c[1]))
    b.append(d)

bb = b
e = [0]*(n-1)
h = []
for _ in range(n):
    h.append([])
count = 0
visited = []

for i, name in enumerate(bb):
    #if len(name) == 1:
    #    count += 1
    #    visited.append(i)
    #else:
        for j in name:
            e[j-1] += 1
            h[j-1].append(i)

while e != [0]*(n-1):
    g = e.index(max(e))
    for i in h[g]:
        if i in visited:
            continue
        else:
            this_bb = bb[i]
            visited.append(i)
            for j in bb[i]:
                e[j-1] -= 1
    count += 1

print(count)


# Optimized solution
n, m = list(map(int, input().split()))
box = [list(map(int, input().split())) for i in range(m)]

box = sorted(box, key=lambda x: x[1])
count, cut = 0, 0

for x, y in box:
    if cut <= x:
        count += 1
        cut = y

print(count)
# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n,m = LI()
    a = LIR(m)
    d = [0 for i in range(n+1)]
    a.sort()
    for i in range(m):
        d[a[i][0]] = i
    for i in range(n):
        d[i+1] = max(d[i],d[i+1])
    for i in range(n):
        a.sort(key = lambda x:x[1])
        mi = a[0][1]-1
        l = d[mi]-(m-len(a))
        a.sort(key = lambda x:x[0])
        a = a[l+1:]
        if len(a) == 0:
            print((i+1))
            quit()
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n,m = LI()
    a = LIR(m)
    a.sort(key = lambda x:x[1])
    x = 0
    ans = 0
    for i in range(m):
        if a[i][0] >= x:
            x = a[i][1]
            ans += 1
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()
# Original solution
# -*- coding: utf-8 -*-

N,M = list(map(int, input().split()))
abM = [list(map(int, input().split())) for i in range(M)]

abM.sort(key = lambda x: (x[0], x[1]))

tmp_e = abM[0][1]
cnt = 1

for i in range(1,M):
    if tmp_e > abM[i][0]:
        tmp_e = min(abM[i][1], tmp_e)
    else:
        cnt += 1
        tmp_e = abM[i][1]
print(cnt)

# Optimized solution
# -*- coding: utf-8 -*-

N,M = list(map(int, input().split()))
abM = [list(map(int, input().split())) for i in range(M)]

abM.sort()

tmp_e = abM[0][1]
cnt = 1

for i in range(1,M):
    if tmp_e > abM[i][0]:
        tmp_e = min(abM[i][1], tmp_e)
    else:
        cnt += 1
        tmp_e = abM[i][1]
print(cnt)
# Original solution
n,m=list(map(int,input().split()))

ab=[]
for _ in range(m):
    a,b=list(map(int,input().split()))
    ab.append([a,b])

ab.sort()

ll=ab[0][0]
rr=ab[0][1]

cnt=1
#print(ab[0],ll,rr,cnt)
for item in ab[1:]:
    l=item[0]
    r=item[1]
    if l>=rr:
        cnt+=1
        ll=l
        rr=r
    else:
        if r<rr:
            rr=r
        if ll<l:
            ll=l
    #print(item,ll,rr,cnt)

print(cnt)



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

ab=[]
for _ in range(m):
    a,b=list(map(int,input().split()))
    ab.append([a,b])

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

cnt=0
border=0

for item in ab:
    if item[0]>=border:
        border=item[1]
        cnt+=1

print(cnt)
# Original solution
N,M = list(map(int, input().split()))
l_table = [False for _ in range(N)]
r_table = [False for _ in range(N)]
lr_table = {}
for _ in range(M):
    l_n, r_n = list(map(int, input().split()))
    l_table[l_n-1] = True
    r_table[r_n-1] = True
    lr_table[(l_n-1,r_n-1)] = True

ret = 0
lefts = []
for i in range(N):
    if lefts and r_table[i] and any([(left,i) in lr_table and lr_table[(left,i)] for left in lefts]):
        # print(i,lefts)
        ret += 1
        lefts = []
    if l_table[i]:
        lefts.append(i)

print(ret)

# Optimized solution
N,M = list(map(int, input().split()))
r_table = [-1]*N
for _ in range(M):
    l_n, r_n = list(map(int, input().split()))
    r_table[r_n-1] = max(l_n-1, r_table[r_n-1])

ret = 0
left = -1
for i in range(N):
    if left < r_table[i]:
        ret += 1
        left = i-1

print(ret)
# Original solution
islands, requests = list(map(int, input().split(" ")))
req = []
for r in range(requests):
    a, b = list(map(int, input().split(" ")))
    req.append([a, b])
req = sorted(req, key = lambda x:x[1])
answer = 1
temp_end = req[0][1]
for r in req:
    if r[0] >= temp_end:
        temp_end = r[1]
        answer += 1
print(answer)

# Optimized solution
length, req = list(map(int, input().split(" ")))
target = []
for i in range(req):
    s, e = list(map(int, input().split(" ")))
    target.append([s, e])
target.sort(key = lambda x: x[1])
answer = 0
before_e = -1
for s, e in target:
    # print(before_e, s, e)
    if s < before_e:
        answer += 1
    else:
        before_e = e
print((req - answer))
# Original solution
# https://atcoder.jp/contests/abc103/tasks/abc103_d
import sys

def solve():
    pairs.sort(key=lambda pair: pair[1])
    done = set()
    cnt = 0
    i = 0
    while i < m:
        if i in done:
            i += 1
            continue
        _, b0 = pairs[i]
        cnt += 1
        done.add(i)
        for j, (a, _) in enumerate(pairs[i+1:], start=(i+1)):
            if a < b0:
                done.add(j)
    return cnt

n, m = map(int, input().split())
pairs = [tuple(int(c) for c in input().split()) for _ in range(m)]
print(n, pairs, file=sys.stderr)
print(solve())


# Optimized solution
# https://atcoder.jp/contests/abc103/tasks/abc103_d
import sys

def solve():
    pairs.sort(key=lambda pair: pair[1])
    cnt = 0
    base = 0
    for (a, b) in pairs:
        if a >= base:
            cnt += 1
            base = b
    return cnt

n, m = map(int, input().split())
pairs = [tuple(int(c) for c in input().split()) for _ in range(m)]
print(n, pairs, file=sys.stderr)
print(solve())
# Original solution
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, M = [int(x) for x in input().split()]
AB = []
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a - 1, b - 2))

AB.sort(key=lambda x: -x[0])

cnt = 0
while len(AB) != 0:
    cut = AB[0][0]
    # print("AB:{}, cut:{}".format(AB, cut))
    # print(AB)
    newAB = []
    for (a,b) in AB:
        if a <= cut and cut <= b:
            pass
        else:
            newAB.append((a, b))
    AB = newAB
    cnt += 1

print(cnt)


# Optimized solution
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, M = [int(x) for x in input().split()]
AB = []
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a - 1, b - 2))

AB.sort(key=lambda x: (-x[0], x[1]))

cnt = 0
i = 0
while i < len(AB):
    cut = AB[i][0]
    while i < len(AB) and AB[i][1] >= cut:
        i += 1
    cnt += 1

print(cnt)
# Original solution
n,m=list(map(int,input().split(' ')))
war=[tuple(map(int,input().split(' '))) for _ in range(m)]
war.sort(key=lambda x:x[1])
bridge=[0]*n
for w in war:
    if not 1 in set(bridge[w[0]:w[1]]):
        bridge[w[1]-1]=1
print((sum(bridge)))

# Optimized solution
n,m=list(map(int,input().split(' ')))
war=[tuple(map(int,input().split(' '))) for _ in range(m)]
war.sort(key=lambda x:x[1])
bridge=[0]*n
flag=0
for w in war:
    if not w[0]<=flag<w[1]:
        flag=w[1]-1
        bridge[flag]=1
print((sum(bridge)))
# Original solution
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]

islands = [set() for _ in range(n + 1)]

for _ in range(m):
    ab = [int(x) for x in input().split()]
    islands[min(ab)].add(max(ab))

ans = 0

for i in range(1, n):
    if i + 1 in islands[i]:
        ans += 1
    else:
        islands[i + 1] = islands[i] | islands[i + 1]

ans += len(islands[n])

print(ans)


# Optimized solution
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]

islands = [set() for _ in range(n + 1)]

for _ in range(m):
    ab = [int(x) for x in input().split()]
    islands[min(ab)].add(max(ab))

ans = 0

for i in range(1, n):
    if i + 1 in islands[i]:
        ans += 1
    elif len(islands[i]) > 0:
        islands[i + 1].add(min(islands[i]))

ans += len(islands[n])

print(ans)
# Original solution
N, M = list(map(int, input().split()))
ans_list = []
for m in range(M):
  a, b = list(map(int, input().split()))

  flag = True
  tmp = {int(i) for i in range(a, b)}
  for i in range(len(ans_list)):
    if ans_list[i] & tmp != set([]):
      ans_list[i] = ans_list[i] & tmp
      flag = False
  if flag:
    ans_list.append(tmp)
print((len(ans_list)))


# Optimized solution
N, M = list(map(int, input().split()))
ab_list = []

for _ in range(M):
  a, b = list(map(int, input().split()))
  ab_list.append((a, b))

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

b = -1
ans = 0
for tupl in ab_list:
  if b == -1:
    ans += 1
    b = tupl[1]
  elif b == tupl[1]:
    continue
  elif b != tupl[1]:
    if tupl[0] <= b-1:
      continue
    else:
      ans += 1
      b = tupl[1]
print(ans)