Problem:
Score : 900 points

Problem Statement

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.

Sample Input 1

5 2
01001
2 4
3 5

Sample Output 1

6

After the first operation, S can be one of the following three: 01001, 00101 and 00011.

After the second operation, S can be one of the following six: 01100, 01010, 01001, 00011, 00101 and 00110.

Sample Input 2

9 3
110111110
1 4
4 6
6 9

Sample Output 2

26

Sample Input 3

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

Sample Output 3

143

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll N = 100010;
ll bit[100010];
void add(ll a, ll w) {
	a++;
	for (ll x = a; x <= N; x += x & -x) bit[x] += w;
}
ll sum(ll a) {
	a++;
	ll ret = 0;
	for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}
// return the sum of [a, b)
ll sum(ll a, ll b) {
	ll ret = 0;
	if(b == 0) return 0;
	ret += sum(b - 1);
	if(a) ret -= sum(a - 1);
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<ll> cons(n, -1);
	REP(i, n) cons[i] = i;
	REP(i, m) {
		ll l, r;
		cin >> l >> r;
		l--; r--;
		cons[l] = max(cons[l], r);
	}
	ll tmp = -1;
	REP(i, n) {
		if(cons[i] > tmp) {
			tmp = cons[i];
		} else cons[i] = -1;
	}
	REP(i, n) if(s[i] == '1') add(i, 1);
	tmp = -1; // どこまで見た
	vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
	dp[0][0] = 1;
	REP(i, n) {
		ll diff = 0;
		if(cons[i] != -1) {
			diff += sum(tmp + 1, cons[i] + 1);
			tmp = cons[i];
		}
		REP(j, n + 1) {
			dp[i][j] %= MOD;
			ll one = j + diff;
			if(one) dp[i + 1][one - 1] += dp[i][j];
			if(tmp - i + 1 > one) dp[i + 1][one] += dp[i][j];
		}
	}
	cout << dp[n][0] % MOD << endl;
	return 0;
}

/* --------------------------------------- */