from functools import reduce

from operator import itemgetter



N, M = list(map(int, input().split()))

a, b = list(zip(*(list(map(int, input().split())) for _ in range(M))))

ts = sorted(zip(a, b), key=itemgetter(1))

ans = reduce(

    lambda acc, t: acc if t[0] < acc[1] else (acc[0] + 1, t[1]),

    ts,

    (0, 0)

)[0]

print(ans)

from functools import reduce

from operator import itemgetter



N, M = list(map(int, input().split()))

a, b = (

    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else

    ((), ())

)



# bについてソートし、橋を取り除く必要があれば可能な限り東の橋を取り除く

ans, _ = reduce(

    lambda acc, q: (

        (acc[0] + 1, q[1]) if q[0] >= acc[1] else

        acc

    ),

    sorted(zip(a, b), key=itemgetter(1)),

    (0, 0)

)



print(ans)

from functools import reduce
from operator import itemgetter

N, M = list(map(int, input().split()))
a, b = list(zip(*(list(map(int, input().split())) for _ in range(M))))
ts = sorted(zip(a, b), key=itemgetter(1))
ans = reduce(lambda acc, t: acc if t[0] < acc[1] else (acc[0] + 1, t[1]), ts, (0, 0))[0]
print(ans)

from functools import reduce
from operator import itemgetter

N, M = list(map(int, input().split()))
a, b = (
    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else ((), ())
)
# bについてソートし、橋を取り除く必要があれば可能な限り東の橋を取り除く
ans, _ = reduce(
    lambda acc, q: ((acc[0] + 1, q[1]) if q[0] >= acc[1] else acc),
    sorted(zip(a, b), key=itemgetter(1)),
    (0, 0),
)
print(ans)

-a, b = list(zip(*(list(map(int, input().split())) for _ in range(M)))) -ts = sorted(zip(a, b), key=itemgetter(1)) -ans = reduce(lambda acc, t: acc if t[0] < acc[1] else (acc[0] + 1, t[1]), ts, (0, 0))[0] +a, b = ( +    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else ((), ()) +) +# bについてソートし、橋を取り除く必要があれば可能な限り東の橋を取り除く +ans, _ = reduce( +    lambda acc, q: ((acc[0] + 1, q[1]) if q[0] >= acc[1] else acc), +    sorted(zip(a, b), key=itemgetter(1)), +    (0, 0), +)