n,m=input().split()

n=int(n)

m=int(m)

l=[]

for i in range(m):

    t=input().split()

    l.append((int(t[0]),int(t[1])))

l.sort()

i=0

res=0

flag=False

while True:

    ra=l[i][1]

    while l[i][0]<ra:

        if i==m-1:

            flag=True

            break

        ra=min(ra,l[i][1])

        i+=1

    res+=1

    if flag:

        break

print(res)

s=input().split()

n=int(s[0])

m=int(s[1])

l=[]

for i in range(m):

    s=input().split()

    l.append((int(s[1]),int(s[0])))

l.sort()

o=[]

for p in l:

    if len(o)>0 and p[0]>=o[-1]>p[1]:

        continue

    else:

        o.append(p[0])

print((len(o)))

n, m = input().split()
n = int(n)
m = int(m)
l = []
for i in range(m):
    t = input().split()
    l.append((int(t[0]), int(t[1])))
l.sort()
i = 0
res = 0
flag = False
while True:
    ra = l[i][1]
    while l[i][0] < ra:
        if i == m - 1:
            flag = True
            break
        ra = min(ra, l[i][1])
        i += 1
    res += 1
    if flag:
        break
print(res)

s = input().split()
n = int(s[0])
m = int(s[1])
l = []
for i in range(m):
    s = input().split()
    l.append((int(s[1]), int(s[0])))
l.sort()
o = []
for p in l:
    if len(o) > 0 and p[0] >= o[-1] > p[1]:
        continue
    else:
        o.append(p[0])
print((len(o)))

-n, m = input().split() -n = int(n) -m = int(m) +s = input().split() +n = int(s[0]) +m = int(s[1]) -    t = input().split() -    l.append((int(t[0]), int(t[1]))) +    s = input().split() +    l.append((int(s[1]), int(s[0]))) -i = 0 -res = 0 -flag = False -while True: -    ra = l[i][1] -    while l[i][0] < ra: -        if i == m - 1: -            flag = True -            break -        ra = min(ra, l[i][1]) -        i += 1 -    res += 1 -    if flag: -        break -print(res) +o = [] +for p in l: +    if len(o) > 0 and p[0] >= o[-1] > p[1]: +        continue +    else: +        o.append(p[0]) +print((len(o)))