import sys input = sys.stdin.readline n, m = map(int, input().split()) edges = [[x - 1 for x in map(int, input().split())] for _ in [0] * m] plans = sorted(edges, key=lambda x : x[1]) now = 0 ans = 2 * (n - 1) for x, y in plans: if(now > x): continue now = y ans -= 1 print(ans)