#include <bits/stdc++.h>
using namespace std;
char str[10005];
int a[10005], b[10005];
int Count() {
  int cnt = 0, len = strlen(str);
  for (int i = 0; i < len; i++) {
    if (str[i] == '1') cnt++;
  }
  return cnt;
}
int main() {
  int n;
  scanf("%d%s", &n, str);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  int res = Count();
  for (int j = 1; j <= 1000; j++) {
    for (int i = 1; i <= n; i++) {
      if ((j >= b[i]) && ((j - b[i]) % a[i] == 0)) {
        if (str[i - 1] == '1') {
          str[i - 1] = '0';
        } else
          str[i - 1] = '1';
      }
    }
    res = max(res, Count());
  }
  cout << res << endl;
  return 0;
}
