#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int l[3005], r[3005];
ll ncr[3005][3005];
ll dp[3005][3005];
char buf[3005];
int cu[3005];
int n, m;

ll slv(int at, int ones)
{
	if (at == m) return 1;
	if (dp[at][ones]) return dp[at][ones];
	if (r[at] >= l[at+1])
	{
		int lim = min(l[at+1]-l[at], ones);
		for (int i = max(0, ones-r[at]+l[at+1]-1);i <= lim;i++)
		{
			dp[at][ones] += slv(at+1, ones-i+cu[r[at+1]]-cu[r[at]])*ncr[l[at+1]-l[at]][i];
			dp[at][ones] %= MOD;
		}
	} else
	{
		dp[at][ones] = ncr[r[at]-l[at]+1][ones] * slv(at+1, cu[r[at+1]]-cu[l[at+1]-1]);
		dp[at][ones] %= MOD;
	}
	return dp[at][ones];
}

int main()
{
	ncr[0][0] = 1;
	for (int i = 1;i < 3005;i++)
	{
		ncr[i][0] = 1;
		for (int j = 1;j <= i;j++) ncr[i][j] = (ncr[i-1][j-1] + ncr[i-1][j]) % MOD;
	}
	scanf("%d%d%s", &n, &m, buf);
	for (int i = 0;i < m;i++) scanf("%d%d", l+i, r+i), --l[i], --r[i];
	for (int i = 1;i < m;i++) r[i] = max(r[i], r[i-1]);
	for (int i = 0;i < n;i++) cu[i] = buf[i]-'0';
	for (int i = 1;i < n;i++) cu[i] += cu[i-1];
	l[m] = r[m] = n;
	printf("%lld\n", slv(0, cu[r[0]]-(l[0]?cu[l[0]-1]:0)));
	return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

There is a string S of length N consisting of characters `0` and `1`. You will perform the following operation for each i = 1, 2, ..., m:

* Arbitrarily permute the characters within the substring of S starting at the l_i-th character from the left and extending through the r_i-th character.



Here, the sequence l_i is non-decreasing.

How many values are possible for S after the M operations, modulo 1000000007(= 10^9+7)?

Constraints

* 2≦N≦3000
* 1≦M≦3000
* S consists of characters `0` and `1`.
* The length of S equals N.
* 1≦l_i < r_i≦N
* l_i ≦ l_{i+1}

Input

The input is given from Standard Input in the following format:


N M
S
l_1 r_1
:
l_M r_M


Output

Print the number of the possible values for S after the M operations, modulo 1000000007.

Examples

Input

5 2
01001
2 4
3 5


Output

6


Input

9 3
110111110
1 4
4 6
6 9


Output

26


Input

11 6
00101000110
2 4
2 3
4 7
5 6
6 10
10 11


Output

143

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int l[3005], r[3005];
ll ncr[3005][3005];
ll dp[3005][3005];
char buf[3005];
int cu[3005];
int n, m;

ll slv(int at, int ones)
{
	if (at == m) return 1;
	if (dp[at][ones]) return dp[at][ones];
	if (r[at] >= l[at+1])
	{
		int lim = min(l[at+1]-l[at], ones);
		for (int i = max(0, ones-r[at]+l[at+1]-1);i <= lim;i++)
		{
			dp[at][ones] += slv(at+1, ones-i+cu[r[at+1]]-cu[r[at]])*ncr[l[at+1]-l[at]][i];
			dp[at][ones] %= MOD;
		}
	} else
	{
		dp[at][ones] = ncr[r[at]-l[at]+1][ones] * slv(at+1, cu[r[at+1]]-cu[l[at+1]-1]);
		dp[at][ones] %= MOD;
	}
	return dp[at][ones];
}

int main()
{
	ncr[0][0] = 1;
	for (int i = 1;i < 3005;i++)
	{
		ncr[i][0] = 1;
		for (int j = 1;j <= i;j++) ncr[i][j] = (ncr[i-1][j-1] + ncr[i-1][j]) % MOD;
	}
	scanf("%d%d%s", &n, &m, buf);
	for (int i = 0;i < m;i++) scanf("%d%d", l+i, r+i), --l[i], --r[i];
	for (int i = 1;i < m;i++) r[i] = max(r[i], r[i-1]);
	for (int i = 0;i < n;i++) cu[i] = buf[i]-'0';
	for (int i = 1;i < n;i++) cu[i] += cu[i-1];
	l[m] = r[m] = n;
	printf("%lld\n", slv(0, cu[r[0]]-(l[0]?cu[l[0]-1]:0)));
	return 0;
}

```