#!/usr/bin/python3

# This is a reference solution to Carl's Cryogenics Corporation Calculator

year = int(input())
n = int(input())

births = []
deaths = []

for i in range(0,n):
    line = input().split(" ")
    a = int(line[0])
    births.append(a)
    b = int(line[1])
    deaths.append(b)

births.sort()
deaths.sort()

bptr = 0
dptr = 0
alive = 0
bdone = False
ddone = False

while dptr < len(deaths) and not(ddone):
    # Process Births first
    if not bdone and bptr < len(births) and births[bptr] <= deaths[dptr]:
        if births[bptr] <= year:
            alive += 1
            # print("Alive", str(births[bptr]), str(alive))
            bptr += 1
        else:
            # print("Births Done")
            bdone = True
    else:
        if deaths[dptr] < year:
            alive -= 1
            # print("Death", str(deaths[dptr]), str(alive))
            dptr += 1
        else:
            # print("Deaths Done")
            dptr = len(deaths) - 1
            ddone = True

print(alive)
b33d0d796f3a8e4d2c4a9e989ec8730ced7e7dd5
<mask token>

<mask token>
for i in range(0, n):
    line = input().split(' ')
    a = int(line[0])
    births.append(a)
    b = int(line[1])
    deaths.append(b)
births.sort()
deaths.sort()
<mask token>
while dptr < len(deaths) and not ddone:
    if not bdone and bptr < len(births) and births[bptr] <= deaths[dptr]:
        if births[bptr] <= year:
            alive += 1
            bptr += 1
        else:
            bdone = True
    elif deaths[dptr] < year:
        alive -= 1
        dptr += 1
    else:
        dptr = len(deaths) - 1
        ddone = True
print(alive)

year = int(input())
n = int(input())
births = []
deaths = []
for i in range(0, n):
    line = input().split(' ')
    a = int(line[0])
    births.append(a)
    b = int(line[1])
    deaths.append(b)
births.sort()
deaths.sort()
bptr = 0
dptr = 0
alive = 0
bdone = False
ddone = False
while dptr < len(deaths) and not ddone:
    if not bdone and bptr < len(births) and births[bptr] <= deaths[dptr]:
        if births[bptr] <= year:
            alive += 1
            bptr += 1
        else:
            bdone = True
    elif deaths[dptr] < year:
        alive -= 1
        dptr += 1
    else:
        dptr = len(deaths) - 1
        ddone = True
print(alive)

#!/usr/bin/python3

# This is a reference solution to Carl's Cryogenics Corporation Calculator

year = int(input())
n = int(input())

births = []
deaths = []

for i in range(0,n):
    line = input().split(" ")
    a = int(line[0])
    births.append(a)
    b = int(line[1])
    deaths.append(b)

births.sort()
deaths.sort()

bptr = 0
dptr = 0
alive = 0
bdone = False
ddone = False

while dptr < len(deaths) and not(ddone):
    # Process Births first
    if not bdone and bptr < len(births) and births[bptr] <= deaths[dptr]:
        if births[bptr] <= year:
            alive += 1
            # print("Alive", str(births[bptr]), str(alive))
            bptr += 1
        else:
            # print("Births Done")
            bdone = True
    else:
        if deaths[dptr] < year:
            alive -= 1
            # print("Death", str(deaths[dptr]), str(alive))
            dptr += 1
        else:
            # print("Deaths Done")
            dptr = len(deaths) - 1
            ddone = True

print(alive)