#include <bits/stdc++.h>
using namespace std;
int N;
string s;
int res[11111];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> s;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    int st = s[i] - '0';
    for (int j = 0; j < b; j++) {
      if (st) res[j]++;
    }
    int cnt = 0;
    st = 1 - st;
    for (int j = b; j < 10000; j++) {
      if (st) res[j]++;
      cnt++;
      if (cnt == a) {
        st = 1 - st;
        cnt = 0;
      }
    }
  }
  int r = 0;
  for (int i = 0; i < 10000; i++) r = max(r, res[i]);
  cout << r;
  return 0;
}
