#include <bits/stdc++.h>
using namespace std;
struct Node {
  int a, b;
  bool s;
} l[202];
int n, ans;
char s[202];
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l[i].a, &l[i].b);
    if (s[i] == '1')
      l[i].s = true;
    else
      l[i].s = false;
  }
  for (int t = 0; t < 130; t++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if ((t - l[i].b) >= 0 && (t - l[i].b) % l[i].a == 0) {
        l[i].s = !l[i].s;
      }
      if (l[i].s) cnt++;
    }
    ans = max(ans, cnt);
  }
  printf("%d", ans);
  return 0;
}
