#include <bits/stdc++.h>
using namespace std;
int add(int _a, int _b) {
  _a = (_a + 1000000007) % 1000000007;
  _b = (_b + 1000000007) % 1000000007;
  return (_a + _b) % 1000000007;
}
int mul(int _a, int _b) {
  _a = (_a + 1000000007) % 1000000007;
  _b = (_b + 1000000007) % 1000000007;
  return ((long long int)((long long int)_a * (long long int)_b)) % 1000000007;
}
int n, A[102], B[102];
char str[102];
void input() {
  int i, j;
  scanf("%d", &n);
  scanf("%s", str);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &A[i], &B[i]);
  }
}
void solve() {
  int i, j, cnt = 0, mx = -1;
  int f, c;
  for (i = 0; i <= 100000; i++) {
    for (j = 0, cnt = 0; j < n; j++) {
      if (i - B[j] < 0) {
        cnt += (str[j] - '0');
        continue;
      }
      f = str[j] == '0' ? 0 : 1;
      c = ((i - B[j]) / A[j]) % 2;
      c ^= 1;
      if ((c ^ f) == 1) {
        cnt++;
      }
    }
    mx = max(mx, cnt);
  }
  printf("%d", mx);
  puts("");
}
int main() {
  input();
  solve();
}
