n,m,*t=list(map(int,open(0).read().split()))

c=d=0

for b,a in sorted([(b,a)for a,b in zip(*[iter(t)]*2)]):

	if a>d:c+=1;d=b-1

print(c)
n,m,*t=list(map(int,open(0).read().split()));r=[n+1]*(n+1)

for a,b in zip(*[iter(t)]*2):

	r[a]=min(r[a],b)

a=0;cur=n+1

for i in range(n+1):

	cur=min(cur, r[i])

	if i==cur:

		cur=r[i]

		a+=1

print(a)
n, m, *t = list(map(int, open(0).read().split()))
c = d = 0
for b, a in sorted([(b, a) for a, b in zip(*[iter(t)] * 2)]):
    if a > d:
        c += 1
        d = b - 1
print(c)

n, m, *t = list(map(int, open(0).read().split()))
r = [n + 1] * (n + 1)
for a, b in zip(*[iter(t)] * 2):
    r[a] = min(r[a], b)
a = 0
cur = n + 1
for i in range(n + 1):
    cur = min(cur, r[i])
    if i == cur:
        cur = r[i]
        a += 1
print(a)

-c = d = 0 -for b, a in sorted([(b, a) for a, b in zip(*[iter(t)] * 2)]): -    if a > d: -        c += 1 -        d = b - 1 -print(c) +r = [n + 1] * (n + 1) +for a, b in zip(*[iter(t)] * 2): +    r[a] = min(r[a], b) +a = 0 +cur = n + 1 +for i in range(n + 1): +    cur = min(cur, r[i]) +    if i == cur: +        cur = r[i] +        a += 1 +print(a)