#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin.ignore();
  getline(cin, s);
  vector<int> a(n);
  vector<int> b(n);
  int len = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    len = max(len, (a[i] + b[i]));
  }
  len *= 1000;
  vector<int> ans(len);
  for (int i = 0; i < len; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    int digit = s[i] - '0';
    int count = 0;
    for (int j = 0; j < len; j++) {
      if (j < b[i]) {
        ans[j] += digit;
        if (j == b[i] - 1) {
          digit = digit ^ 1;
        }
      } else {
        if (count == a[i]) {
          count = 0;
          digit = digit ^ 1;
        }
        ans[j] += digit;
        count++;
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans[len - 1] << endl;
  return 0;
}
