#include <bits/stdc++.h>
using namespace std;
struct light {
  int a, b;
  char s;
  bool onoff;
} lgt[105];
int main() {
  int n;
  cin >> n;
  int initial = 0;
  for (int i = 0; i < n; i++) {
    cin >> lgt[i].s;
    if (lgt[i].s == '1') initial++;
  }
  for (int i = 0; i < n; i++) {
    cin >> lgt[i].a >> lgt[i].b;
    if (lgt[i].s == '1')
      lgt[i].onoff = true;
    else
      lgt[i].onoff = false;
  }
  int maxL = 0, cnt;
  for (int t = 1; t < 1000; t++) {
    cnt = 0;
    for (int i = 0; i < n; i++) {
      if (t >= lgt[i].b && (t - lgt[i].b) % lgt[i].a == 0) {
        if (lgt[i].onoff)
          lgt[i].onoff = false;
        else
          lgt[i].onoff = true;
      }
      if (lgt[i].onoff) cnt++;
    }
    if (maxL < cnt) maxL = cnt;
  }
  cout << max(maxL, initial) << endl;
  return 0;
}
