#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  pair<int, int> a[1000];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  int ans = 0;
  for (int i = 0; i < 1000000; i++) {
    int sum = 0;
    for (int l = 0; l < n; l++) {
      int k = i - a[l].second;
      if (k < 0) {
        sum += s[l] - '0';
        continue;
      }
      k /= a[l].first;
      k = k % 2;
      k = 1 - k;
      sum += k ^ (s[l] - '0');
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
