#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 3030;
typedef long long ll;
const int mod = 1e9 + 7;
inline void reduce(int & x) {
	x += x >> 31 & mod;
}
int n, m;
char c[maxn];
int max[maxn], s[maxn];
int f[maxn][maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> c[i];
		s[i] = s[i - 1] + c[i] % 2;
		max[i] = i;
	}
	rep(i, 1, m) {
		int l, r;
		cin >> l >> r;
		max[l] = std::max(max[l], r);
	}
	f[1][s[max[1]]] = 1;
	rep(i, 1, n) {
		max[i + 1] = std::max(max[i + 1], max[i]);
		int lol = s[max[i + 1]] - s[max[i]];
		rep(j, 0, n) {
			if(j != 0) { 
				reduce(f[i + 1][j + lol - 1] += f[i][j] - mod);
			}
			if(i + j - 1 != max[i]) {
				reduce(f[i + 1][j + lol] += f[i][j] - mod);
			}
		}
	}
	cout << f[n + 1][0] << '\n';
}

### Prompt

Develop a solution in Cpp to the problem described below:

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>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 3030;
typedef long long ll;
const int mod = 1e9 + 7;
inline void reduce(int & x) {
	x += x >> 31 & mod;
}
int n, m;
char c[maxn];
int max[maxn], s[maxn];
int f[maxn][maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> c[i];
		s[i] = s[i - 1] + c[i] % 2;
		max[i] = i;
	}
	rep(i, 1, m) {
		int l, r;
		cin >> l >> r;
		max[l] = std::max(max[l], r);
	}
	f[1][s[max[1]]] = 1;
	rep(i, 1, n) {
		max[i + 1] = std::max(max[i + 1], max[i]);
		int lol = s[max[i + 1]] - s[max[i]];
		rep(j, 0, n) {
			if(j != 0) { 
				reduce(f[i + 1][j + lol - 1] += f[i][j] - mod);
			}
			if(i + j - 1 != max[i]) {
				reduce(f[i + 1][j + lol] += f[i][j] - mod);
			}
		}
	}
	cout << f[n + 1][0] << '\n';
}

```