#include <bits/stdc++.h>
using namespace std;
struct light {
  int a, b;
  int st;
};
int main() {
  int n;
  cin >> n;
  vector<light> v(n);
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) v[i].st = s[i] - '0';
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v[i].a = a;
    v[i].b = b;
  }
  int mx = 0;
  for (auto el : v) mx += el.st;
  for (int t = 0; t < 100000; t++) {
    int on = 0;
    for (auto &el : v) {
      if (el.b <= t && (t - el.b) % el.a == 0) el.st = 1 - el.st;
      if (el.st) on++;
    }
    mx = max(mx, on);
  }
  cout << mx << endl;
}
