Under construction

Still being built. Things may change

Decrease the Boss Strength

Time limit1.5sMemory limit1024 MB

Summary
Count the orderings of spell uses that bring N down to zero, where spell i subtracts a_i and needs N divisible by 2^b_i.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation, Math
Solved
No attempts yet

Problem

Fulano, an avid gamer, has come across an epic challenge in the online game "Boss Challenge". The goal is to defeat a powerful boss, whose power is described by a set of ancient runes. These runes represent a giant binary number NN, which is the total strength of the enemy.

To defeat the boss, Fulano has MM different spells at his disposal. The goal is to reduce the total strength of the enemy to zero using these spells. The ii-th spell is described by two integers aia_i and bib_i. When used, the ii-th spell reduces the value of NN by aia_i. A spell can be used as many times as the player wants, as long as two conditions hold:

  • The value of aia_i is less than or equal to the current value of NN.
  • The current value of NN is divisible by 2bi2^{b_i}. In other words, spell ii can only be used if the last bib_i binary digits of NN are zeros.

Fulano wants to know how many different ways he can combine the spells to reduce the binary number NN to exactly zero. Two combinations are considered different if the order in which the spells are used is different.

The number of combinations can be very large, so the answer should be printed modulo 109+710^9 + 7.

Help Fulano find the answer.

Input

The first line contains a single integer NN (1≤N≤10181 \le N \le 10^{18}), the power of the boss.

The second line contains a single integer MM (1≤M≤1051 \le M \le 10^5), the number of spells.

Each of the next MM lines contains two integers aia_i (1≤ai≤1001 \le a_i \le 100) and bib_i (0≤bi≤600 \le b_i \le 60).

Output

Print the number of different sequences of spell uses that reduce the power of the boss from NN to 00, modulo 109+710^9 + 7.

Examples2

  1. Example 1

    Input
    6 2
    1 0
    2 1
    
    Expected output
    8
    
  2. Example 2

    Input
    9 5
    1 0
    1 1
    4 3
    1 1
    8 0
    
    Expected output
    92