from collections import defaultdict



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

disputes = defaultdict(int)

for i in range(m):

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

    disputes[b] = max(disputes[b], a)

ans = 0

most_right_bridge = 0

for b in sorted(disputes.keys()):

    if most_right_bridge <= disputes[b]:

        ans += 1

        most_right_bridge = b

print(ans)

import sys

from collections import defaultdict



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

disputes = defaultdict(int)

for line in sys.stdin.readlines():

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

    if disputes[b] < a:

        disputes[b] = a

ans = 0

most_right_bridge = 0

for b in sorted(disputes.keys()):

    if most_right_bridge <= disputes[b]:

        ans += 1

        most_right_bridge = b

print(ans)

from collections import defaultdict

n, m = list(map(int, input().split()))
disputes = defaultdict(int)
for i in range(m):
    a, b = list(map(int, input().split()))
    disputes[b] = max(disputes[b], a)
ans = 0
most_right_bridge = 0
for b in sorted(disputes.keys()):
    if most_right_bridge <= disputes[b]:
        ans += 1
        most_right_bridge = b
print(ans)

import sys
from collections import defaultdict

n, m = list(map(int, input().split()))
disputes = defaultdict(int)
for line in sys.stdin.readlines():
    a, b = list(map(int, line.split()))
    if disputes[b] < a:
        disputes[b] = a
ans = 0
most_right_bridge = 0
for b in sorted(disputes.keys()):
    if most_right_bridge <= disputes[b]:
        ans += 1
        most_right_bridge = b
print(ans)

+import sys -for i in range(m): -    a, b = list(map(int, input().split())) -    disputes[b] = max(disputes[b], a) +for line in sys.stdin.readlines(): +    a, b = list(map(int, line.split())) +    if disputes[b] < a: +        disputes[b] = a