#include <bits/stdc++.h>
using namespace std;
int used[200];
signed main() {
  int n;
  cin >> n;
  int sum = 0;
  bool second[n];
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    second[i] = (c == '1');
    sum += second[i];
  }
  pair<int, int> a[n];
  for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
  int max = sum;
  for (int i = 1; i < 1e5; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i >= a[j].second && (i - a[j].second) % a[j].first == 0) {
        sum -= second[j];
        second[j] = !second[j];
        sum += second[j];
      }
    }
    max = std::max(max, sum);
  }
  cout << max << endl;
}
