#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int va[110], vb[110], bb[110], v[110];
char str[110];
int main() {
  scanf("%d", &n);
  int i, j, k;
  scanf("%s", str + 1);
  for (i = 1; i <= n; i++)
    if (str[i] == '1') v[i] = 1, m++;
  for (i = 1; i <= n; i++) scanf("%d%d", &va[i], &vb[i]), bb[i] = vb[i];
  ans = m;
  for (k = 1; k <= 1000; k++) {
    for (i = 1; i <= n; i++) {
      bb[i]--;
      if (bb[i] == 0) {
        bb[i] = va[i];
        m -= v[i], v[i] ^= 1, m += v[i];
      }
    }
    ans = max(ans, m);
  }
  printf("%d\n", ans);
  return 0;
}
