This page is still under construction.

Parts of this page are still being built. What you see may change.

Laying Tiles

Interview

Time limit1sMemory limit1024 MB

Summary
Count tilings of a 2 by n corridor with 1x2 and 1x1 tiles, given some 1x1 tiles already placed, modulo 1e9+7.
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics, Math, Prefix sum
Solved
No attempts yet

Problem

During renovations at the Information Technology Laboratory, construction workers must replace damaged floor tiles in a laboratory corridor measuring 2 × n meters. The workers have an unlimited supply of tiles in two sizes: 1 × 2 meters and 1 × 1 meter. A 1 × 2 meter tile may be rotated 90 degrees before being laid and placed either along or across the corridor.

The workers have already begun the repairs and have laid k tiles of size 1 × 1 in some places on the corridor floor. To finish the repairs, the foreman needs to prepare a plan for the remaining work. To do this, he must decide how to lay tiles on the places where none have been laid yet. This can be done in various ways, and the foreman wants to go through all the options and choose the best one. Before doing so, the foreman wants to know how many options he will have to consider. This number must be found modulo 109 + 7.

Write a program that, given the corridor length n and the positions of the tiles already laid, determines the number of ways to lay tiles on the remaining places. The answer must be printed modulo 109 + 7.

Input

The first line of the input file contains two integers: n, the length of the corridor, and k, the number of unit tiles already laid (1 ≤ n ≤ 100 000, 0 ≤ k < 2n).

The following k lines contain two integers each, xi and yi, which give the positions of the already laid unit tiles. The i-th tile is laid at the xi-th meter of the corridor in the yi-th row (1 ≤ xi ≤ n, 1 ≤ yi ≤ 2).

Output

The output file must contain a single integer: the number of ways to lay tiles in the corridor, taken modulo 109 + 7.

Hint

Figure 1. All ways to lay tiles in the first example

Figure 2. All ways to lay tiles in the third example. An already laid tile is marked in gray.

Examples3

  1. Example 1

    Input
    2 0
    
    Expected output
    7
    
  2. Example 2

    Input
    3 0
    
    Expected output
    22
    
  3. Example 3

    Input
    3 1
    2 1
    
    Expected output
    8