#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

ll dp[3005][3005], mm = 1e9+7;
//dp[i][j] = fixed all before i, from [i, n] there are j 1's
int n, m, num[3005], r[3005], a, b;
string s;
vector<pi> v;

void add(ll &a, ll b) {
	b %= mm;
	a += b;
	a %= mm;
}

int main() {
	cin >> n >> m >> s;
	FOR(i, 0, n-1) r[i] = i;
	FOR(i, 1, m) {
		cin >> a >> b; a--; b--;
		if (v.empty()) v.pb(pi(a, b));
		else if (v.back().f == a) v.back().s = max(v.back().s, b);
		else if (v.back().s < b) v.pb(pi(a, b));
	}
	for(auto it:v) r[it.f] = it.s;
	FOR(i, 1, n-1) r[i] = max({i, r[i], r[i-1]});
	
	num[0] = (s[0] == '1');
	FOR(i, 1, n-1) num[i] = num[i-1] + (s[i] == '1');

	dp[0][num[n-1]] = 1;
	FOR(i, 0, n-1) FOR(j, 0, num[n-1]) {
		if (dp[i][j] == 0) continue;
		int inr = j - (num[n-1] - num[r[i]]);
		if (inr > 0) add(dp[i+1][j-1], dp[i][j]);
		if (r[i] - i + 1 > inr) add(dp[i+1][j], dp[i][j]);
	}
	cout << dp[n][0];
}

### Prompt

Your task is to create 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;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

ll dp[3005][3005], mm = 1e9+7;
//dp[i][j] = fixed all before i, from [i, n] there are j 1's
int n, m, num[3005], r[3005], a, b;
string s;
vector<pi> v;

void add(ll &a, ll b) {
	b %= mm;
	a += b;
	a %= mm;
}

int main() {
	cin >> n >> m >> s;
	FOR(i, 0, n-1) r[i] = i;
	FOR(i, 1, m) {
		cin >> a >> b; a--; b--;
		if (v.empty()) v.pb(pi(a, b));
		else if (v.back().f == a) v.back().s = max(v.back().s, b);
		else if (v.back().s < b) v.pb(pi(a, b));
	}
	for(auto it:v) r[it.f] = it.s;
	FOR(i, 1, n-1) r[i] = max({i, r[i], r[i-1]});
	
	num[0] = (s[0] == '1');
	FOR(i, 1, n-1) num[i] = num[i-1] + (s[i] == '1');

	dp[0][num[n-1]] = 1;
	FOR(i, 0, n-1) FOR(j, 0, num[n-1]) {
		if (dp[i][j] == 0) continue;
		int inr = j - (num[n-1] - num[r[i]]);
		if (inr > 0) add(dp[i+1][j-1], dp[i][j]);
		if (r[i] - i + 1 > inr) add(dp[i+1][j], dp[i][j]);
	}
	cout << dp[n][0];
}

```