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

itv=[]

for i in range(m):

  a,b=list(map(int,input().split()))

  start=min(a,b)

  end=max(a,b)

  itv.append([end,start])

t,ans=0,0

itv=sorted(itv)

for e,s in itv:

  if t<=s:

    t=e

    ans+=1

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

itv=[]

for i in range(m):

  a,b=list(map(int,input().split()))

  itv+=[(b,a)]

itv=sorted(itv)

cnt=0

l=1

for t,s in itv:

  if l<=s:

    l=t

    cnt+=1

print(cnt)
n, m = list(map(int, input().split()))
itv = []
for i in range(m):
    a, b = list(map(int, input().split()))
    start = min(a, b)
    end = max(a, b)
    itv.append([end, start])
t, ans = 0, 0
itv = sorted(itv)
for e, s in itv:
    if t <= s:
        t = e
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
itv = []
for i in range(m):
    a, b = list(map(int, input().split()))
    itv += [(b, a)]
itv = sorted(itv)
cnt = 0
l = 1
for t, s in itv:
    if l <= s:
        l = t
        cnt += 1
print(cnt)

-    start = min(a, b) -    end = max(a, b) -    itv.append([end, start]) -t, ans = 0, 0 +    itv += [(b, a)] -for e, s in itv: -    if t <= s: -        t = e -        ans += 1 -print(ans) +cnt = 0 +l = 1 +for t, s in itv: +    if l <= s: +        l = t +        cnt += 1 +print(cnt)