Counting Bow Ties

Count 4-cycles in a bipartite graph defined by M rectangles over vertex ranges, with N up to 1e9.

Hard8GeometryCombinatoricsSortingPrefix sumNo attempts yetTime limit2sMemory limit256 MB

Problem

A bipartite graph has 2N2N vertices. NN of them hang from the ceiling and the other NN sit on the floor. The ceiling vertices are numbered 1 through NN, and the floor vertices are numbered the same way.

MM trapezoids connect the ceiling to the floor. Each trapezoid is given by the segment [sx,ex][s_x, e_x] it occupies on the ceiling and the segment [sy,ey][s_y, e_y] it occupies on the floor. Ceiling vertex ii and floor vertex jj are joined by an edge when at least one trapezoid satisfies both sxiexs_x \le i \le e_x and syjeys_y \le j \le e_y. When several trapezoids cover the same edge, the edge still counts once.

A simple cycle of length 4 in this graph is called a bow tie. Two different ceiling vertices i1i_1, i2i_2 and two different floor vertices j1j_1, j2j_2 form one bow tie when all four edges (i1,j1)(i_1, j_1), (i1,j2)(i_1, j_2), (i2,j1)(i_2, j_1), (i2,j2)(i_2, j_2) are present. Two bow ties are different when their edge sets differ in at least one element.

Given the shape of the graph, count the bow ties.

A graph with 9 vertices on each side and two trapezoids. The dashed lines mark one bow tie in it.

Input

The first line contains NN (1N1091 \le N \le 10^9) and MM (0M10000 \le M \le 1000), separated by a space. The graph has 2N2N vertices and there are MM trapezoids.

Each of the next MM lines contains one trapezoid in the form sxs_x exe_x sys_y eye_y (1sxexN1 \le s_x \le e_x \le N, 1syeyN1 \le s_y \le e_y \le N).

Output

Print the number of bow ties modulo 109+710^9 + 7.