#include <bits/stdc++.h>
using namespace std;
int main() {
  int c[10001] = {0}, n, ans = 0;
  cin >> n;
  int a[n], b[n], p[n];
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    p[i] = s[i] - '0';
  }
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  for (int i = 0; i <= 10000; i++) {
    int count = 0;
    for (int j = 0; j < n; j++) {
      if (i < b[j]) {
        count += p[j];
      } else {
        int l = i - b[j];
        if (l % a[j] == 0) p[j] = 1 - p[j];
        count += p[j];
      }
    }
    ans = max(ans, count);
  }
  cout << ans << endl;
}
