#include <bits/stdc++.h>
using namespace std;
int a[110], b[110];
int timer[110];
bool light[110];
int n;
int lights() {
  int ret = 0;
  for (int i = 0; i < n; ++i) ret += light[i];
  return ret;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string str;
  cin >> n >> str;
  for (int i = 0; i < n; ++i) light[i] = (str[i] == '1');
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    timer[i] = b[i];
  }
  int ans = lights();
  for (int i = 0; i < 100000; ++i) {
    for (int j = 0; j < n; ++j) {
      timer[j]--;
      if (timer[j] == 0) {
        light[j] = (light[j] ^ 1);
        timer[j] = a[j];
      }
    }
    ans = max(ans, lights());
  }
  cout << ans << endl;
}
