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



ab=[]

for _ in range(m):

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

    ab.append([a,b])



ab.sort()



ll=ab[0][0]

rr=ab[0][1]



cnt=1

#print(ab[0],ll,rr,cnt)

for item in ab[1:]:

    l=item[0]

    r=item[1]

    if l>=rr:

        cnt+=1

        ll=l

        rr=r

    else:

        if r<rr:

            rr=r

        if ll<l:

            ll=l

    #print(item,ll,rr,cnt)



print(cnt)



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



ab=[]

for _ in range(m):

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

    ab.append([a,b])



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



cnt=0

border=0



for item in ab:

    if item[0]>=border:

        border=item[1]

        cnt+=1



print(cnt)



n, m = list(map(int, input().split()))
ab = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    ab.append([a, b])
ab.sort()
ll = ab[0][0]
rr = ab[0][1]
cnt = 1
# print(ab[0],ll,rr,cnt)
for item in ab[1:]:
    l = item[0]
    r = item[1]
    if l >= rr:
        cnt += 1
        ll = l
        rr = r
    else:
        if r < rr:
            rr = r
        if ll < l:
            ll = l
    # print(item,ll,rr,cnt)
print(cnt)

n, m = list(map(int, input().split()))
ab = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    ab.append([a, b])
ab.sort(key=lambda x: x[1])
cnt = 0
border = 0
for item in ab:
    if item[0] >= border:
        border = item[1]
        cnt += 1
print(cnt)

-ab.sort() -ll = ab[0][0] -rr = ab[0][1] -cnt = 1 -# print(ab[0],ll,rr,cnt) -for item in ab[1:]: -    l = item[0] -    r = item[1] -    if l >= rr: +ab.sort(key=lambda x: x[1]) +cnt = 0 +border = 0 +for item in ab: +    if item[0] >= border: +        border = item[1] -        ll = l -        rr = r -    else: -        if r < rr: -            rr = r -        if ll < l: -            ll = l -    # print(item,ll,rr,cnt)