#include <bits/stdc++.h>
using namespace std;
const int N = 102;
const int S = 120 * 120;
int r[N], t[N];
char a[N];
int main() {
  int n, i, j, s;
  scanf("%d", &n);
  scanf("%s", a + 1);
  for (i = 1; i <= n; i++) scanf("%d%d", &r[i], &t[i]);
  for (i = 1, s = 0; i <= n; i++)
    if (a[i] == '1') ++s;
  int ans = s;
  for (j = 1; j <= S; j++) {
    for (i = 1; i <= n; i++)
      if (j >= t[i] && (j - t[i]) % r[i] == 0) {
        if (a[i] == '1')
          a[i] = '0', --s;
        else
          a[i] = '1', ++s;
      }
    ans = max(ans, s);
  }
  printf("%d", ans);
  return 0;
}
