Crossing Diagonals

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a regular polygon with nn vertices, and mm of its diagonals have been selected. Count how many pairs of the selected diagonals cross each other. Two diagonals cross when they intersect strictly inside the polygon; two diagonals that share only a common vertex (endpoint) are not counted as crossing.

Write a program that:

  • reads the description of the polygon and the selected diagonals from standard input,
  • counts the number of pairs of diagonals that cross,
  • writes that number to standard output.

Input

The first line contains two integers nn and mm, separated by a single space, where nn is the number of vertices of the polygon and mm is the number of selected diagonals (4n10000004 \le n \le 1\,000\,000, 2m100000002 \le m \le 10\,000\,000).

Each of the next mm lines describes one diagonal. The ii-th of these lines contains two integers aia_i and bib_i (1ai,bin1 \le a_i, b_i \le n), separated by a single space, denoting the diagonal that joins vertex aia_i with vertex bib_i. The vertices of the polygon are numbered from 11 to nn in counter-clockwise order.

You may assume that every pair of numbers describes a valid diagonal (never a single vertex, and never an edge of the polygon), and that all diagonals in the input are distinct.

Output

Print a single integer: the number of pairs of selected diagonals that cross. If no pair of diagonals crosses, print 00.

Hint

In the picture above, the solid lines and the dashed lines show two different sets of selected diagonals on the same polygon.