#include <bits/stdc++.h>
using namespace std;
int n, a[105], b[105], c[105], tot, ans;
char s[105];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    c[i] = s[i] - '0';
    if (c[i] == 1) tot++;
  }
  ans = tot;
  for (int i = 1; i <= 125; i++) {
    for (int j = 1; j <= n; j++) {
      if (i < b[j]) continue;
      int k = i - b[j];
      if (k % a[j] != 0) continue;
      tot -= c[j];
      c[j] ^= 1;
      tot += c[j];
    }
    ans = max(ans, tot);
  }
  printf("%d\n", ans);
}
