#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[3114][3514], ct[3100];
signed main(){
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	vector< pair<int,int> > p;
	int cur = -1;
	for(int i=0;i<m;i++){
		int xx,yy;
		cin>>xx>>yy;
		if( i > 0 && p.back().first == xx ){
			if( p.back().second < yy ){
				p.pop_back();
			}
		}
		if( cur < yy ){
			p.pb(mp(xx,yy));
			cur = yy;
		}
	}
	vector<int> lefs;
	for(int i=0;i<p.size();i++){ lefs.pb(p[i].first); }
	for(int i=1;i<=n;i++){
		if( s[i-1] == '1') ct[i] = ct[i-1]+1;
		else ct[i] = ct[i-1];
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		int idx = upper_bound(lefs.begin(),lefs.end(),i)-lefs.begin();
		if( idx == 0 || p[idx-1].second < i){
			dp[i][ct[i]] += dp[i-1][ct[i-1]];
			dp[i][ct[i]] %= inf;
		}
		else{
			int rig = p[idx-1].second;
			for(int j=0;j<=n;j++){
				if( ct[rig] >= j+1 ){
					dp[i][j+1] += dp[i-1][j];
					dp[i][j+1] %= inf;
				}
				if( rig - ct[rig] >= i-j ){
					dp[i][j] += dp[i-1][j];
					dp[i][j] %= inf;
				}
			}
		}
	}
	cout<<dp[n][ct[n]]<<endl;
	return 0;
}
### Prompt

Generate 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>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[3114][3514], ct[3100];
signed main(){
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	vector< pair<int,int> > p;
	int cur = -1;
	for(int i=0;i<m;i++){
		int xx,yy;
		cin>>xx>>yy;
		if( i > 0 && p.back().first == xx ){
			if( p.back().second < yy ){
				p.pop_back();
			}
		}
		if( cur < yy ){
			p.pb(mp(xx,yy));
			cur = yy;
		}
	}
	vector<int> lefs;
	for(int i=0;i<p.size();i++){ lefs.pb(p[i].first); }
	for(int i=1;i<=n;i++){
		if( s[i-1] == '1') ct[i] = ct[i-1]+1;
		else ct[i] = ct[i-1];
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		int idx = upper_bound(lefs.begin(),lefs.end(),i)-lefs.begin();
		if( idx == 0 || p[idx-1].second < i){
			dp[i][ct[i]] += dp[i-1][ct[i-1]];
			dp[i][ct[i]] %= inf;
		}
		else{
			int rig = p[idx-1].second;
			for(int j=0;j<=n;j++){
				if( ct[rig] >= j+1 ){
					dp[i][j+1] += dp[i-1][j];
					dp[i][j+1] %= inf;
				}
				if( rig - ct[rig] >= i-j ){
					dp[i][j] += dp[i-1][j];
					dp[i][j] %= inf;
				}
			}
		}
	}
	cout<<dp[n][ct[n]]<<endl;
	return 0;
}
```