#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, a[N], b[N];
char s[N];
int cur[N * N];
bool last = false;
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    last = s[i] - '0';
    if (s[i] == '1') cur[0]++;
    for (int j = 1; j < N * N; j++) {
      if (j == b[i]) {
        last ^= 1;
      } else if (j > b[i] && (j - b[i]) % a[i] == 0)
        last ^= 1;
      if (last == 1) cur[j]++;
    }
  }
  int mx = 0;
  for (int i = 0; i < N * N; i++) {
    mx = max(mx, cur[i]);
  }
  cout << mx << endl;
  return 0;
}
