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

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

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

c=a=0

while c<m:

    i=1

    t=s[0][1]

    while i<len(s)and s[i][0]<t:

        t=min(t,s[i][1])

        i+=1

    c+=i

    s=s[i:]

    a+=1

print(a)
x=c=0

for b,a in sorted([[*list(map(int,t.split()))][::-1]for t in open(0)][1:]):

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

print(c)
n, m = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(m)]
s.sort(key=lambda x: x[0])
c = a = 0
while c < m:
    i = 1
    t = s[0][1]
    while i < len(s) and s[i][0] < t:
        t = min(t, s[i][1])
        i += 1
    c += i
    s = s[i:]
    a += 1
print(a)

x = c = 0
for b, a in sorted([[*list(map(int, t.split()))][::-1] for t in open(0)][1:]):
    if a > x:
        x = b - 1
        c += 1
print(c)

-n, m = list(map(int, input().split())) -s = [list(map(int, input().split())) for _ in range(m)] -s.sort(key=lambda x: x[0]) -c = a = 0 -while c < m: -    i = 1 -    t = s[0][1] -    while i < len(s) and s[i][0] < t: -        t = min(t, s[i][1]) -        i += 1 -    c += i -    s = s[i:] -    a += 1 -print(a) +x = c = 0 +for b, a in sorted([[*list(map(int, t.split()))][::-1] for t in open(0)][1:]): +    if a > x: +        x = b - 1 +        c += 1 +print(c)