import sys from collections import defaultdict def main(): N, M = map(int, sys.stdin.readline().split()) operations = [] s = set() for _ in range(M): B, C = map(int, sys.stdin.readline().split()) if C > B: operations.append((B, C)) s.add(B) s.add(C) # No valid operations if not s: print(N * (N + 1) // 2) return sorted_v = sorted(s, reverse=True) b_to_cs = defaultdict(list) for B, C in operations: b_to_cs[B].append(C) max_val = {} for v in sorted_v: current_max = v for C in b_to_cs.get(v, []): c_max = max_val.get(C, C) if c_max > current_max: current_max = c_max max_val[v] = current_max total = N * (N + 1) // 2 for v in s: total += (max_val[v] - v) print(total) if __name__ == "__main__": main()