#include <bits/stdc++.h>
using namespace std;
bool np[110];
int n, ans, a[110], b[110];
char s[110];
void solve() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  for (int t = 1, cnt; t <= 1000; ++t) {
    cnt = 0;
    for (int i = 1; i <= n; ++i) {
      if (s[i] == '1') ++cnt;
    }
    ans = max(ans, cnt);
    for (int i = 1; i <= n; ++i) {
      if (t - b[i] >= 0 && (t - b[i]) % a[i] == 0) {
        s[i] = '1' - s[i] + '0';
      }
    }
  }
  printf("%d", ans);
}
int main() {
  solve();
  return 0;
}
