n, m = map(int, input().split()) operations = [] for _ in range(m): b, c = map(int, input().split()) operations.append((b, c)) # Sort operations by C in descending order operations.sort(key=lambda x: -x[1]) max_map = {} for b, c in operations: current_b = max_map.get(b, b) current_c = max_map.get(c, c) if current_c > current_b: max_map[b] = current_c total = n * (n + 1) // 2 sum_diff = 0 for key in max_map: sum_diff += (max_map[key] - key) print(total + sum_diff)