#D8182. Digital Clock

    ID: 6804 Type: Default 5000ms 134MiB

Digital Clock

Digital Clock

C: Digital Clock

story

Aizu Nyan has recently caught a cold. I can't get out of bed because I'm too lazy. The spicy appearance is also cute.

However, Aizu Nyan, who had no choice but to spare time, came up with a way to play with the digital clock under the pillow. The number of glowing bars of a digital clock as shown in the figure below is counted every second, just earnestly.

After playing this game for several hours, Aizu Nyan noticed that the number of glowing sticks may be the same even if the time is different. I was wondering how many times the number of glowing sticks was the same, and Aizunyan asked you to count it while you were nursing.

For Aizu Nyan who can't get out of bed, you decide to write a program and ask for it.

problem

There is a digital clock like the one shown above that displays the year, month, day, and hour, minute, and second. Answer how many years, months, days, minutes, and seconds the number of glowing bars is exactly N. However, since the digital clock is partially broken, there are some sticks that never shine. Note that even if the display looks the same depending on the non-illuminating stick, if the year, month, day, hour, minute, and second you tried to display are different, they are counted separately.

The shining parts of each number are as shown in the following figure.

Digital clocks display the year in 0-sized 4 digits (0000 to 9999) and month, day, hour, minute, and second in 0-sized 2 digits.

The month starts on the 1st, April, 6, 9, November until the 30th, and 1, 3, 5, 7, 8, 10, December until the 31st. February is usually up to 28th, but leap years are up to 29th. Here, a leap year is the following year.

  1. A year in which the Christian era is divisible by 400 is a leap year.
  2. The year is not divisible by 400, but the year divisible by 100 is not a leap year.
  3. The year is not divisible by 100, but the year divisible by 4 is a leap year.
  4. A year in which the Christian era is not divisible by 4 is not a leap year.

The hours are from 0:00 to 23:00, the minutes are from 0 to 59 minutes, and the seconds are from 0 to 59 seconds. You don't have to think about leap seconds.

Input format

The number of glowing bars N (0 ≤ N ≤ 98) is given in the first line.

The number of broken parts K (0 ≤ K ≤ 98) is given in the second line, and then the information of the broken parts is given in the K line. On the i-th line of the K line, the digit p_i (0 ≤ p_i ≤ 13) and the position q_i (0 ≤ q_i ≤ 6) of the i-th broken bar are given, separated by blanks.

The digit is the ID assigned to each number of the digital clock as shown in the following figure, and is the number assigned from 0 to 13 in order from the highest number.

The position of the bar is the ID of the bar in each number as shown in the following figure, and is the number assigned the numbers from 0 to 6 in order from the upper bar.

Output format

Output the total number of years, months, hours, minutes, seconds, and seconds when the number of glowing bars is exactly N on one line.

Input example 1

28 0

Output example 1

1

It is one way of 11:11:11 on November 11, 1111.

Input example 2

28 1 2 0

Output example 2

2

There are two ways: 11:11:11 on November 11, 1171, and 11:11:11 on November 11, 1111.

Input example 3

98 1 3 0

Output example 3

0

Input example 4

60 1 3 0

Output example 4

13362470370

Example

Input

28 0

Output

1

inputFormat

Input format

The number of glowing bars N (0 ≤ N ≤ 98) is given in the first line.

The number of broken parts K (0 ≤ K ≤ 98) is given in the second line, and then the information of the broken parts is given in the K line. On the i-th line of the K line, the digit p_i (0 ≤ p_i ≤ 13) and the position q_i (0 ≤ q_i ≤ 6) of the i-th broken bar are given, separated by blanks.

The digit is the ID assigned to each number of the digital clock as shown in the following figure, and is the number assigned from 0 to 13 in order from the highest number.

The position of the bar is the ID of the bar in each number as shown in the following figure, and is the number assigned the numbers from 0 to 6 in order from the upper bar.

outputFormat

Output format

Output the total number of years, months, hours, minutes, seconds, and seconds when the number of glowing bars is exactly N on one line.

Input example 1

28 0

Output example 1

1

It is one way of 11:11:11 on November 11, 1111.

Input example 2

28 1 2 0

Output example 2

2

There are two ways: 11:11:11 on November 11, 1171, and 11:11:11 on November 11, 1111.

Input example 3

98 1 3 0

Output example 3

0

Input example 4

60 1 3 0

Output example 4

13362470370

Example

Input

28 0

Output

1

样例

28
0
1