#include <bits/stdc++.h>
using namespace std;
int popcount(string &str) {
  int c = 0;
  for (int i = 0; str[i]; i++) {
    if (str[i] == '1') c++;
  }
  return c;
}
int main() {
  int n, i, j, c = 48, r = 0, m;
  cin >> n;
  int a[n], b[n];
  string str;
  cin >> str;
  for (i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  m = popcount(str);
  int time = 0;
  while (++time <= 125) {
    for (i = 0; str[i]; i++) {
      if (time == b[i]) {
        str.at(i) = 48 + (str.at(i) + 1) % 2;
        b[i] += a[i];
      }
    }
    m = max(m, popcount(str));
  }
  cout << m;
}
