Problem:
 Score : 400 points    Problem Statement There are N islands lining up from west to east, connected by N-1 bridges.  The i -th bridge connects the i -th island from the west and the (i+1) -th island from the west.  One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:  Request i : A dispute took place between the a_i -th island from the west and the b_i -th island from the west. Please make traveling between these islands with bridges impossible.  You decided to remove some bridges to meet all these M requests.  Find the minimum number of bridges that must be removed.      Constraints  All values in input are integers.  2 \leq N \leq 10^5  1 \leq M \leq 10^5  1 \leq a_i < b_i \leq N  All pairs (a_i, b_i) are distinct.         Input Input is given from Standard Input in the following format:  N  M  a_1  b_1  a_2  b_2  :  a_M  b_M       Output Print the minimum number of bridges that must be removed.        Sample Input 1 5 2
1 4
2 5      Sample Output 1 1  The requests can be met by removing the bridge connecting the second and third islands from the west.       Sample Input 2 9 5
1 8
2 7
3 5
4 6
7 9      Sample Output 2 2       Sample Input 3 5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5      Sample Output 3 4

Solution (Python):









_, m = map(int, input().split())
interval = []
for _ in range(m):
    interval.append(list(map(int, input().split())))
interval = sorted(interval, key=lambda x: x[1])
divide_pos = -1
ans = 0
for itv in interval:
    if divide_pos < itv[0]:
        ans += 1
        divide_pos = itv[1] - 1
print(ans)

Solution (Python):
n,m = map(int,input().split())
a = [[0,0] for i in range(m)]
for i in range(m) :
  a0,a1 = map(int,input().split())
  a[i][:] = a0-1,a1-1

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

ans = [0 for i in range(n-1)]
ans[a[0][1]-1] = 1
right = a[0][1]-1
for i in range(1,m) :
  if right < a[i][0] :
    ans[a[i][1]-1] = 1
    right = a[i][1]-1
    
print(sum(ans))

Solution (Python):
def main():
    N, M = map(int, input().split())
    kukan_list = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])
    ans = 0
    cut = 0
    
    for kukan in kukan_list:
        if cut >= kukan[0]:
            continue
        ans += 1
        cut = kukan[1] - 1
    
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N,M=map(int,input().split())

ng_dic={}
for i in range(M):
  a,b=map(int,input().split())
  if not a in ng_dic:
    ng_dic[a]=b
  else:
    ng_dic[a]=min(b,ng_dic[a])
    
ng_dic=sorted(ng_dic.items())


answer=0
right=N+1
for key,value in ng_dic:
  
  right=min(right,value)
  
  if key>=right:
    answer+=1
    right=value
  
print(answer+1)

Solution (Python):
n,m = map(int,input().split())
data = []
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    data.append((a,b))
data = sorted(data,key=lambda x:x[1])
cnt = 0
dis = -1
for i in range(m):
    a,b = data[i]
    if(dis < a):
        cnt += 1
        dis = b - 1
print(cnt)

Solution (Python):
N,M = map(int,input().split())
bridges = [list(map(int,input().split())) for _ in range(M)]
bridges.sort(key=lambda x: x[1])
cut = -1
ans = 0
for b in bridges:
    if b[0] <= cut <= b[1]:
        continue
    else:
        cut = b[1]-1 
        ans += 1
print(ans)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline

from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

n,m = myinput()
ab = [ list(myinput()) for _ in range(m) ]


ab_sorted = mysort(ab,1)


count = 0
e = 0
for i in range(m):
    ns = ab_sorted[i][0]
    ne = ab_sorted[i][1]
    if ns>=e:
        count += 1
        e = ne
    else:
        pass
print(count)

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

ba.sort()
removed_id = 0 
ans = 0
for b, a in ba:
  if a >= removed_id:
    ans += 1
    removed_id = b

print(ans)

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

ab.sort(key=lambda x:x[1])
cnt=0
dis=-1
for i in range(M):
  if dis<ab[i][0]:
    cnt+=1
    dis=ab[i][1]-1
print(cnt)

Solution (Python):
n,m = map(int,input().split())
data = []
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    data.append((a,b))
data = sorted(data,key=lambda x:x[1])
cnt = 0
dis = -1
for i in range(m):
    a,b = data[i]
    if(dis < a):
        cnt += 1
        dis = b - 1
print(cnt)

Solution (Python):
n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1])

remove = ab[0][1]
res = 1
for i in range(m):
    if remove <= ab[i][0]:
        res += 1
        remove = ab[i][1]

print(res)

Solution (Python):
n,m = map(int,input().split())
data = []
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    data.append((b,a))
data.sort()
cnt = 0
dis = -1
for i in range(m):
    b,a = data[i]
    if(dis < a):
        cnt += 1
        dis = b - 1
print(cnt)

Solution (Python):
n,m=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)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1])
    
    ans = 0
    pre = -1
    for a, b in ab:
        if a >= pre:
            ans += 1
            pre = b
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab = sorted(ab, key=lambda x:x[1])
ans = 0
left, right = ab[0]
for a, b in ab[1:]:
    if a <= left and right <= b:
        continue
    if left < a and right > a:
        left = a 
        right = min(right, b)
    else:
        ans += 1
        left = a 
        right = b
print(ans+1)

Solution (Python):

N,M=map(int,input().split())
AB=[]

for i in range(M):
    AB.append(list(map(int,input().split())))

AB.sort()

INF=10**9
ans=0
bottom=INF

for i in range(M):
    a,b=AB[i]
    
    if a>=bottom:
        ans+=1
        bottom=INF
    
    bottom=min(bottom,b)

print(ans+1)

Solution (Python):
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab.sort(key=lambda x:(x[1]))
c = 0
brid = -1
for a,b in ab:
    if a > brid:
        c += 1
        brid = b-1
print(c)

Solution (Python):
import numpy as np

def main():
  N,M = map(int,input().split())
  ab=[]
  for _ in range(M):
    a,b = map(int,input().split())
    ab.append([b,a])
  ab.sort()
  tmp=0
  count = 0
  for i in range(M):
    if ab[i][1] >= tmp:
      tmp = ab[i][0]
      count += 1
  print(count)

main()

Solution (Python):
N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(key=lambda x: x[1])
cnt = 1
x = AB[0][1]
for a, b in AB:
    if a <= x - 1 <= b and a <= x <= b:
        continue
    else:
        cnt += 1
        x = b
print(cnt)

Solution (Python):
n, m = list(map(int, input().split()))
d = [[0, 0] for _ in range(m)]
for i in range(m):
    d[i] = list(map(int, input().split()))
d.sort(key=lambda x: x[1])
ans = 0
target = 0
for dd in d:
    if target == 0:
        ans += 1
        target = dd[1]
    else:
        if dd[0] >= target:
            ans += 1
            target = dd[1]
print(ans)

Solution (Python):
n,m=map(int,input().split())
ab=[[int(i) for i in input().split()] for _ in range(m)]

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

ans=0
r=-1
for a,b in ab:
    if a>=r:
        ans+=1
        r=b
print(ans)

Solution (Python):
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1])
cnt = 1
cur = A[0][1]
for i in range(1,M):
    if A[i][0]<cur:continue
    cur = A[i][1]
    cnt += 1
print(cnt)

Solution (Python):
n, m = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()] for _ in range(m)]
ab.sort(key=lambda x: x[1])
removed = []
for a, b in ab:
    if not any(a <= x < b for x in removed):
        removed.append(b - 1)
print(len(removed))

Solution (Python):
N, M = map(int, input().split())
S = []
for i in range(M):
    S.append(tuple(map(int, input().split())))

S = sorted(S, key=lambda x: x[1])
res = 1
cur = S[0][1]
for i in range(M):
    if S[i][0] < cur:
        continue
    cur = S[i][1]
    res += 1

print(res)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

B.sort()
ans = 1
tmp = B[0][0]
for upper, lower in B[1:]:
  if lower >= tmp:
      tmp = upper
      ans += 1

print(ans)

Solution (Python):
n, m = map(int, input().split())
LI = []
for _ in range(m):
    b, a = map(int, input().split())
    LI.append([a, b])

LI.sort()

ans = 0
bridge = 0
for i in range(m):
    d, c = LI[i]
    
    if bridge < c:
        bridge = d-1
        ans += 1

print(ans)

Solution (Python):
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)

Solution (Python):
n,m = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(m)]
lst.sort(key=lambda x:x[1])
res = []
for i in range(m):
    a,b = lst[i][0], lst[i][1]
    flg = False
    if i==0:
        res.append(b-1)
    else:
        for r in res:
            if a<=r<=b:
                flg=True
        if not flg:
            res.append(b-1)
print(len(res))

Solution (Python):
import numpy as np
from collections import defaultdict
N, M = list(map(int, input().split()))

edge_dict = defaultdict(set)
A, B = [], []
for i in range(M):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
A = np.array(A)
B = np.array(B)
inds = np.argsort(B)

last_connected_node = 0
cnt = 0
for a, b in zip(A[inds], B[inds]):
    if last_connected_node <= a:
        last_connected_node = b
        cnt += 1
print(cnt)

Solution (Python):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
a.sort()
a = sorted(a, key = lambda x : x[1])
c = a[0][1]
ans = 1
for i in range(1, m):
    if a[i][0] >= c:
        ans += 1
        c = a[i][1]
print(ans)

Solution (Python):
n,m = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(m)]
p.sort()
a1 = p[0][0]
b1 = p[0][1]
ans = 1

for i in range(1,m):
    a2 = p[i][0]
    b2 = p[i][1]
    if b1 <= a2:
        ans += 1
        a1 = a2
        b1 = b2
    else:
        if a1 < a2:
            a1 = a2
        if b1 > b2:
            b1 = b2

print(ans)

Solution (Python):
n, m = map(int, input().split())
spans = [tuple(map(int, input().split())) for _ in range(m)]

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

ans = 0
cur_end = -float("inf")

for st, en in spans:
    if cur_end > st:
        continue
    ans += 1
    cur_end = en
print(ans)

Solution (Python):
from operator import itemgetter

N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
AB.sort(key=itemgetter(1,0))


ans = 1
p = 0
for i in range(1, M):
    if AB[i][0] >= AB[p][1]:
        ans += 1
        p = i
print(ans)

Solution (Python):
N,M=map(int,input().split())
numbers=[]
for _ in range(M):
    a,b=input().split()
    numbers.append([int(b),int(a)])
new_numbers=sorted(numbers)
answers=[]
while new_numbers:
    large = new_numbers[0][0]
    if  not new_numbers[0] in answers:
        answers.append(new_numbers[0])
    new_numbers=[a for a in new_numbers if a[1]>=large]
print(len(answers))

Solution (Python):
N, M = map(int, input().split())

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

from operator import itemgetter
st = sorted(ab, key=itemgetter(1))
last = 0
ans = 0
for s, t in st:
    
    if s >= last:
        ans += 1
        last = t
print(ans)

Solution (Python):
N,M = list(map(int, input().split()))
ab = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1])

bef=-1
cnt = 0
for one in ab:
    if one[0]<=bef and bef<=one[1]:
        continue
    else:
        bef = one[1]-1
        cnt+=1
print(cnt)

Solution (Python):
N,M = map(int,input().split())
ts = [list(map(int,input().split()))[::-1] for i in range(M)]
ts.sort()

count=0
tmp=0

for i in ts:
  if i[1]>=tmp:
    count += 1
    tmp = i[0]
print(count)

Solution (Python):
N, M = map(int, input().split())
S = []
for i in range(M):
    a, b = map(int, input().split())
    S.append([a, b])
    
from operator import itemgetter
S = sorted(S, key=itemgetter(1))
ans = 0
last = -1*float('Inf')
for si in S:
    if si[0] >= last:
        ans += 1
        last = si[1]
print(ans)

Solution (Python):
from operator import itemgetter

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


ab = sorted([tuple(map(int, input().split())) for i in range(m)], key=itemgetter(1))

removed = -1
ans = 0

for a, b in ab:
    
    if a > removed:
        removed = b - 1
        ans += 1

print(ans)

Solution (Python):
n,m = map(int,input().split())
ts = [list(map(int,input().split()))[::-1] for j in range(m)]

ts.sort()

count = 0
t = 0

for j in range(m):
  if ts[j][1]>=t:
    count+=1
    t = ts[j][0]
    
print(count)

Solution (Python):
from sys import stdin

N, M = map(int, stdin.readline().split())
ab = [list(map(int, stdin.readline().split())) for _ in range(M)]

ab.sort()

inf = 10 ** 9

left = -inf
right = inf

ans = 1

for a, b in ab:
    if left <= a and a < right:
        left = a
        if left < b and b <= right:
            right = b
    elif left < b and b <= right:
        right = b
    else:
        ans += 1
        left = a
        right = b

if M == 0:
    print(0)
else:
    print(ans)

Solution (Python):
from sys import stdin

N, M = map(int, stdin.readline().split())
ab = [list(map(int, stdin.readline().split())) for _ in range(M)]

ab.sort()

inf = 10 ** 9

left = -inf
right = inf

ans = 1

for a, b in ab:
    if left <= a and a < right:
        left = a
        if left < b and b < right:
            right = b
    elif left < b and b < right:
        right = b
    else:
        ans += 1
        left = a
        right = b

if M == 0:
    print(0)
else:
    print(ans)

Solution (Python):
from operator import itemgetter

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


ab = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1))

removed = -1
ans = 0

for a in ab:
    
    if a[0] > removed:
        
        removed = a[1] - 1
        ans += 1

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class UnionFind():
    def __init__(self, n):
        self.n = n
        
        
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = MAP()
L = [LIST() for i in range(M)]
A = [0] * N

L = sorted(L, key=lambda x: x[1])
tmp = L[0][1]
ans = 1
for a, b in L:
    if a < tmp <= b:
        continue
    else:
        ans += 1
        tmp = b
print(ans)

Solution (Python):
N, M = map(int, input().split())
section =[]
for i in range(M):
    section.append(list(map(int, input().split())))
section.sort()

ans = 1
b_edge  = section[0][1]
del section[0]

for a, b in section:
    if b_edge<= a:
        b_edge = b
        ans +=1
    elif b < b_edge:
        b_edge = b
    elif a < b_edge <= b:
        b_edge = b_edge
print(ans)

Solution (Python):
N,M = map(int,input().split())
A = []
B = []
all = []
for _ in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    all.append([a,b])
all = sorted(all,key=lambda x:x[1])
MinBar = 1
abar = all[0][0]
bbar = all[0][1]

for i in range(1,M):
    if all[i][0] < bbar:
        bbar = min(bbar,all[i][1])
    else:
        MinBar += 1
        abar = all[i][0]
        bbar = all[i][1]
print(MinBar)

Solution (Python):
n,m = map(int,input().split())
count = 0
t = 0

base = [list(map(int,input().split())) for i in range(m)]

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

for temp in base:
  if t <= temp[0]:
    count = count + 1
    t = temp[1]

print(count)

Solution (Python):
n, m = map(int, input().split())
ab = []
for i in range(m):
	a,b = map(int, input().split())
	ab.append([a,b])
ab = sorted(ab, key=lambda x: x[1])
mn = ab[0][1]
c = 1
for i in ab:
	if i[0] >= mn:
		c += 1
		mn = i[1]
print (c)

Solution (Python):
from operator import itemgetter

n, m = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(m)], key = itemgetter(1))
bridge = 0
ans = 0

for a, b in ab:
    if bridge <= a:
        bridge = b
        ans += 1
        
print(ans)

Solution (Python):
N, M = map(int, input().split())
intervals = [list(map(int, input().split())) for _ in range(M)]
intervals.sort(key=lambda ab: ab[1])
ans = 1
position = intervals[0][1]
for i in range(1,M):
  if position <= intervals[i][0]:
    ans += 1
    position = intervals[i][1]
print(ans)

Solution (Python):
n, m = map(int, input().split())
ab = [list(map(int, list(input().split()))) for i in range(m)]

ab.sort(key=lambda x: x[1])
sub = -1
ans = 0
for i in range(m):
    if ab[i][0] <= sub and ab[i][1] > sub:
        continue
    else:
        ans += 1
        sub = ab[i][1] - 1

print(ans)

Solution (Python):
import sys


N, M = map(int, input().split())
bridge = [[] for _ in range(N)]
for x in sys.stdin.readlines():
    a, b = map(int, x.split())
    a -= 1; b -= 1
    bridge[a].append(b)

ans = 0
near = N
for i in range(N):
    if near == i:
        ans += 1
        near = N
    for e in bridge[i]:
        near = min(near, e)

print(ans)

Solution (Python):
N,M = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(M)]



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

cnt = 0
right = -1
for A,B in AB:
    if A >= right:
        cnt += 1
        right = B

print(cnt)

Solution (Python):
n,m = map(int,input().split())
ab = []
for i in range(m):
    ab.append(list(map(int,input().split())))
cnt = m
ab.sort()
a0 = ab[0][0]
b0  = ab[0][-1]
for a,b in ab[1:]:
    if a < b0:
         cnt -=1
         b0 = min(b0,b)
    else:
        b0 = b
print(cnt)

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    ab_list.sort(key = itemgetter(1))
    del_max = -10
    ans = 0
    for ab in ab_list:
        if ab[0] - 1 > del_max:
            ans += 1
            del_max = ab[1] - 2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
request = [list(map(int, input().split())) for _ in range(m)]

request = sorted(request, key=lambda x:x[1])
broken = -1
ans = 0
for a, b in request:
    if a > broken:
        broken = b - 1
        ans += 1
print(ans)

Solution (Python):
n , m = map(int, input().split())

ranges = [[] for _ in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    ranges[i] = [a,b]
ranges = sorted(ranges, key = lambda x:x[1])
MAX = - float("inf")
ans = 0
for i in range(m):
    if MAX <= ranges[i][0]:
        MAX = ranges[i][1]
        ans += 1
print(ans)

Solution (Python):
n , m = map(int, input().split())

ranges = [[] for _ in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    ranges[i] = [a,b]
ranges = sorted(ranges, key = lambda x:x[1])
MAX = - float("inf")
ans = 0
for i in range(m):
    if MAX < ranges[i][0]:
        MAX = ranges[i][1] - 0.1
        ans += 1
print(ans)

Solution (Python):
n,m = map(int,input().split())
l_rng = []
for i in range(m):
    l_rng.append( list(map(int,input().split()) ) )
l_rng.sort(key=lambda x:x[1])    

r_isl = l_rng[0][1]
cnt = 1

for i in l_rng:
  if  r_isl <= i[0]:
    r_isl = i[1] 
    cnt = cnt + 1
print(cnt)

Solution (Python):
from operator import itemgetter
n, m = map(int, input().split())
yobo = []
for _ in range(m):
    a, b = map(int, input().split())
    yobo.append((a, b))

yobo = sorted(yobo, key=itemgetter(1))
ans = 0
rem = -1

for i in range(m):
    if rem < yobo[i][0]:
        rem = yobo[i][1] - 1
        ans += 1

print(ans)

Solution (Python):
n,m = [int(x) for x in input().split()]
li = []
for _ in range(m):
    li.append([int(x) for x in input().split()])
z = sorted(li,key=lambda x:x[1])
ans = 0
res = 0
for i in z:
    if res < i[0]:
        ans += 1
        res = i[1]-0.5
print(ans)

Solution (Python):
n,m = [int(x) for x in input().split()]
li = []
for _ in range(m):
    li.append([int(x) for x in input().split()])
z = sorted(li,key=lambda x:x[1])
ans = 0
res = 0
for i in z:
    if res < i[0]:
        ans += 1
        res = i[1]-0.5
print(ans)

Solution (Python):
N, M = 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)

Solution (Python):
n,m=map(int,input().split())
A=[[0]*2 for i in range(m)]
for i in range(m):
  A[i]=list(map(int,input().split()))
A.sort(key=lambda x:x[1])
B=[A[0][1]-1]
for i in range(m):
  if A[i][0]<=B[-1] and B[-1]<A[i][1]:
    pass
  else:
    B.append(A[i][1]-1)
print(len(B))

Solution (Python):
import sys
input=sys.stdin.readline
INF = 10**6

def main():
    n,m=map(int,input().split())
    G=[INF]*n
    for _ in range(m):
        a,b=map(int,input().split())
        a-=1
        b-=1
        G[a]=min(G[a],b)
    
    lim=INF
    cnt=0
    for i in range(n):
        if lim==i:
            cnt+=1
            lim=G[i]
        else:
            lim=min(lim,G[i])
    
    print(cnt)
if __name__=='__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
AB=[tuple(map(int,input().split())) for _ in range(m)]

AB=sorted(AB, key=lambda x: x[1])
cnt,cut=0,0

for a,b in AB:
    if cut<=a:
        cnt +=1
        cut=b

print(cnt)

Solution (Python):
import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache




n,m=map(int,input().split())
query=[]
for i in range(m):
    a,b=map(int,input().split())
    query.append([a,b])
query.sort(key=lambda x:x[1])

tekyo=-1
kazu=0
for i in range(m):
    a,b=query[i][0],query[i][1]
    if tekyo<a: 
        tekyo=b-1
        kazu+=1
print(kazu)

Solution (Python):
from collections import deque
def main():
    N,M = map(int,input().split(" "))
    request = []
    for i in range(M):
        a,b = map(int,input().split(" "))
        request.append((b,a))
    request.sort()
    request = deque(request)
    ans = [request.popleft()]
    for i in range(M-1):
        x = request[i][1]
        if x >= ans[-1][0]:
            ans.append(request[i])
    print(len(ans))
if __name__ == "__main__":
    main()

Solution (Python):
N,M = list(map(int, input().split()))
S = []
for _ in range(M):
    A,B = list(map(int, input().split()))
    S.append([A,B])
S = sorted(S, key=lambda x:x[1])

rem = 0
now = 0

for ab in S:
    left = ab[0]
    right = ab[1]
    if left <= now:
        continue
    else:
        now = right -1
        rem += 1

print(rem)

Solution (Python):
from operator import itemgetter

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

requests = [tuple(map(int, input().split())) for _ in range(m)]
requests = sorted(requests, key=itemgetter(1))

counter = 1
now = requests[0][1]
for request in requests[1:]:
    if request[0] >= now:
        now = request[1]
        counter += 1

print(counter)

Solution (Python):

from collections import deque
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
lis = []
for i in range(M):
    a[i], b[i] = map(int, input().split())
    lis.append([a[i], b[i]])

lis = sorted(lis, key=lambda x:x[1])
lis = deque(lis)

start, end = lis.popleft()
cnt = 1

while lis:
    x, y = lis.popleft()
    if x<end:
        continue
    else:
        start = x
        end = y
        cnt += 1

print(cnt)

Solution (Python):
N, M = map(int, input().split())
pairs = []
for _ in range(M):
    i, j = map(int, input().split())
    pairs.append([i, j])

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


current = 0
bag = []
for pair in pairs:
    if pair[0] >= current:
        bag.append(pair)
        current = pair[1]

print(len(bag))

Solution (Python):
n, m = map(int, input().split())
AB = []
for _ in range(m):
    a, b = map(int, input().split())
    AB.append([a,b])
AB = sorted(AB, key=lambda x:x[1])

rem = 0
now = 0

for ab in AB:
    left = ab[0]
    right = ab[1]
    if left <= now:
        pass
    else:
        now = right -1
        rem += 1

print(rem)

Solution (Python):
N, M = map(int,input().split())
ls = [tuple(map(int,input().split())) for _ in range(M)]
ls.sort(key=lambda x:x[1])
l = 0
ans = 0
for a,b in ls:
    if l <= a:
        l = b
        ans += 1
print(ans)

Solution (Python):
N, M, *L = map(int, open(0).read().split())
sheet = [[[],[]] for i in range(N+1)]
for i,m in enumerate(zip(*[iter(L)]*2)):
  sheet[m[0]][0].append(i)
  sheet[m[1]][1].append(i)
ans = 0
log = set()
cnt = set()
for i in range(1,N+1):
  for x in sheet[i][1]:
    if x not in log:
      ans += 1
      log = log.union(cnt)
      cnt = set()
  for x in sheet[i][0]:
    cnt.add(x)
print(ans)

Solution (Python):
N,M = map(int,input().split())
island = [tuple(map(int,input().split())) for _ in range(M)]

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

right = 0
count = 0

for i in range(M):
    if right <= island[i][0]:
        right = island[i][1]
        count += 1

print(count)

Solution (Python):
N,M = list(map(int, input().split(' ')))


bridge=[]

for i in range(M):
    C = list(map(int,input().split(' ')))
    bridge.append(C)



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



temp = 0
ans = 0

for i in range(M):
    if(temp<=bridge[i][0]):
        temp = bridge[i][1]
        ans+=1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
events = []
for i in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    events.append((a, 1, i))
    events.append((b, 0, i))
events.sort()
ans = 0
removed = set()
started = set()
for x, t, i in events:
    if t == 0:
        if i not in removed:
            removed |= started
            started = set()
            ans += 1
    if t == 1:
        started.add(i)
print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
s=[tuple(map(int, input().split())) for i in range(M)]
from operator import itemgetter
s.sort(key=itemgetter(1))
t=0
a=0
for i in s:
    if i[0]>t:
        a+=1
        t=i[1]-1
print(a)

Solution (Python):
N, M = map(int, input().split())

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

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

ans = 0
x = 0
for i in range(M):
    a, b = bridges[i]
    if a >= x:
        x = b
        ans += 1

print(ans)

Solution (Python):
n,m = map(int,input().split())
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[1])

count = 1
memo = ab[0][1]
for i in range(m):
    if i == 0:
        continue
    if memo <= ab[i][0]:
        count += 1
        memo = ab[i][1]
print(count)

Solution (Python):
N,M=map(int,input().split())
ab=[]
for m in range(M):
  [a,b]=[int(i) for i in input().split()]
  ab.append([a,b])
ab.sort(key=lambda x:x[1])
count=[]
count.append(ab[0][1]-1)
for i in range(1,M):
  if ab[i][0]<=count[-1]<ab[i][1]:
    pass
  elif ab[i][0]<=count[-1] and ab[i][1]-1==count[-1]:
    count.remove(count[-1])
    count.append(ab[i][1]-1)
  else:
    count.append(ab[i][1]-1)
print(len(count))

Solution (Python):
import sys
sin = sys.stdin.readline
N, M = map(int, sin().split())
bs = [tuple(map(int, sin().split())) for _ in range(M)]
bs.sort(key=lambda x: x[1])

rbs = []
for a, b in bs:
    if not rbs or a > rbs[-1]:
        rbs.append(b - 1)
ans = len(rbs)
print(ans)

Solution (Python):
N, M = map(int, input().split())
bs = [tuple(map(int, input().split())) for _ in range(M)]
bs.sort(key=lambda x: x[1])

rbs = []
for a, b in bs:
    if not rbs or a > rbs[-1]:
        rbs.append(b - 1)
ans = len(rbs)
print(ans)

Solution (Python):
n ,m = list(map(int, input().split()))
q = []
for i in range(m):
    q.append(list(map(int, input().split())))
q.sort(key=lambda x: x[1])
ans = 0
last_cut_bridge = -1
for i in range(m):
    a,b = q[i]
    if a <= last_cut_bridge <= b:
        continue
    else:
        last_cut_bridge = b-1
        ans += 1
print(ans)

Solution (Python):


[N, M] = [int(i) for i in input().split()]

AB = []
for m in range(M):
    [a, b] = [int(i) for i in input().split()]
    AB.append((a, b))


sorted_AB = sorted(AB, key=lambda ab: ab[1])



removed_bridge_number = 0
easternmost = 0
for (a, b) in sorted_AB:
    
    if a >= easternmost:
        removed_bridge_number += 1
        easternmost = b

print(removed_bridge_number)

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

section=[]

for i in range(m):
    aa,bb=list(map(int,input().split()))
    section.append([aa,bb])

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

maxr=-10**6
cnt=0

for a,b in section:
    if maxr<=a:
        maxr=b
        cnt+=1

print(cnt)