from collections import defaultdict n, m = map(int, input().split()) operations = [] s = set() for _ in range(m): b, c = map(int, input().split()) operations.append((b, c)) s.add(b) s.add(c) sorted_list = sorted(s, reverse=True) b_to_c = defaultdict(list) for b, c in operations: b_to_c[b].append(c) max_reach = {x: x for x in sorted_list} for x in sorted_list: cs = b_to_c.get(x, []) if not cs: continue current_max = max(max_reach.get(c, c) for c in cs) if current_max > max_reach[x]: max_reach[x] = current_max sum_increment = 0 for x in sorted_list: if 1 <= x <= n and max_reach[x] > x: sum_increment += (max_reach[x] - x) initial_sum = n * (n + 1) // 2 print(initial_sum + sum_increment)