n, m = map(int,input().split()) lr = [list(map(int,input().split())) for _ in range(m)] lr.sort(key=lambda x:x[1]) v, ans = 0, 0 for l,r in lr: if not l <= v <= r: v = r ans += 1 print(n-ans)