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