#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string A;
  cin >> A;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> b[i] >> a[i];
  }
  int ans = 0, res = 0;
  for (int i = 0; i < n; i++)
    if (A[i] == '1') ans++;
  res = ans;
  int t = 1, on, off;
  while (t < 1000000) {
    on = 0;
    off = 0;
    for (int i = 0; i < n; i++) {
      if ((t - a[i]) >= 0 && (t - a[i]) % b[i] == 0) {
        if (A[i] == '1')
          A[i] = '0', off++;
        else
          A[i] = '1', on++;
      }
    }
    ans += on - off;
    res = max(res, ans);
    t++;
  }
  cout << res;
  return 0;
}
