#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
clock_t start_time, end_time;
void open() {
  ((void)0);
  ((void)0);
}
void close() {
  ((void)0);
  ((void)0);
  ((void)0);
}
const int MAX = 2e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1);
const long double ERR = 1e-10;
const int move_r[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int move_c[] = {0, -1, 0, 1, -1, 1, -1, 1};
int t, n, a[105], b[105];
char in[105];
int main(int argc, char *argv[]) {
  open();
  scanf("%d %s", &n, in);
  for (int i = 0; i < n; ++i) scanf("%d %d", a + i, b + i);
  int cnt = 0, ans = 0;
  for (int i = 0; i < n; ++i)
    if (in[i] == '1') cnt++;
  ans = cnt;
  for (int i = 1; i <= 500; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i >= b[j] && (i - b[j]) % a[j] == 0) {
        if (in[j] == '1') {
          in[j] = '0';
          cnt--;
        } else {
          in[j] = '1';
          cnt++;
        }
      }
    }
    ans = max(ans, cnt);
  }
  printf("%d\n", ans);
  close();
  return 0;
}
