Pasta

Interview

Time limit1sMemory limit128 MB

Summary
Count sequences of length N over three kinds where no kind appears three or more times in a row, with some positions fixed, modulo 10000.
Level

Medium4 of 10

Topics
Dynamic programming, Implementation
Solved
No attempts yet

Problem

Sanggeun makes pasta for dinner every day. There are three kinds of pasta he can make: tomato sauce, cream sauce, and basil sauce.

He wants to plan the pasta he will eat over the next NN days. Each day he picks one of the three kinds, but because eating the same pasta too many days in a row gets tiring, he never eats the same kind on three or more consecutive days. In other words, any single kind may be eaten on at most two days in a row.

In addition, the pasta for KK of the NN days is fixed in advance.

Given NN and the fixed-day information, write a program that counts the number of possible plans.

Input

The first line contains two integers NN and KK. (3≤N≤1003 \le N \le 100, 1≤K≤N1 \le K \le N)

Each of the next KK lines describes one fixed day in the form Ai BiA_i\ B_i, meaning the pasta eaten on day AiA_i is BiB_i. Here Bi=1B_i = 1 means tomato sauce, 22 means cream sauce, and 33 means basil sauce. All AiA_i are distinct.

Output

Print the number of possible plans modulo 1000010000.

Hint

When N=5N = 5 and the pasta is fixed to tomato on day 1, tomato on day 3, and cream on day 4, the following 6 plans are possible. (Each number is the pasta kind eaten on that day.)

  • 1, 2, 1, 2, 1
  • 1, 2, 1, 2, 2
  • 1, 2, 1, 2, 3
  • 1, 3, 1, 2, 1
  • 1, 3, 1, 2, 2
  • 1, 3, 1, 2, 3

Examples2

  1. Example 1

    Input
    5 3
    3 1
    1 1
    4 2
    
    Expected output
    6
    
  2. Example 2

    Input
    20 5
    10 2
    4 3
    12 1
    13 2
    9 1
    
    Expected output
    2640