n, m = map(int, input().split()) shortcuts = [tuple(map(int, input().split())) for _ in range(m)] shortcuts.sort(key=lambda x: (x[1], x[0])) current_end = 0 count = 0 for a, b in shortcuts: if a >= current_end: count += 1 current_end = b print(2 * (n - 1) - count)