n, m = map(int, input().split()) intervals = [] for _ in range(m): l, r = map(int, input().split()) intervals.append((r, l)) intervals.sort() count = 0 last = -1 for r, l in intervals: if l > last: count += 1 last = r print(n - count)