#include <bits/stdc++.h>
using namespace std;
static int dp[1000006];
static char str[105];
int main() {
  int n;
  scanf("%d %s", &n, str);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    swap(a, b);
    bool cur = false;
    if (str[i] == '1') {
      cur = true;
    }
    for (int j = 0; j < a; j++) {
      dp[j] += cur;
    }
    for (int j = a; j <= 1e6; j++) {
      int dis = (j - a) % b;
      if (dis == 0) {
        cur = !cur;
      }
      dp[j] += cur;
    }
  }
  int ans = 0;
  for (int i = 0; i <= 1e6; i++) {
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
