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

disputes = []

for i in range(m):

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

    disputes.append((b, a))

disputes.sort()

ans = 0

most_right_bridge = 0

for b, a in disputes:

    if most_right_bridge <= a:

        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)

n, m = list(map(int, input().split()))
disputes = []
for i in range(m):
    a, b = list(map(int, input().split()))
    disputes.append((b, a))
disputes.sort()
ans = 0
most_right_bridge = 0
for b, a in disputes:
    if most_right_bridge <= a:
        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)

+from collections import defaultdict + -disputes = [] +disputes = defaultdict(int) -    disputes.append((b, a)) -disputes.sort() +    disputes[b] = max(disputes[b], a) -for b, a in disputes: -    if most_right_bridge <= a: +for b in sorted(disputes.keys()): +    if most_right_bridge <= disputes[b]: