#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> A[105];
string s;
int main() {
  long long n;
  scanf("%lld", &n);
  cin >> s;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &A[i].first);
    scanf("%lld", &A[i].second);
  }
  long long ans = 0, tmp, x;
  for (long long i = 0; i <= 10000; i++) {
    tmp = 0;
    for (long long j = 1; j <= n; j++) {
      if (i < A[j].second) {
        if (s[j - 1] == '1') {
          tmp++;
        }
      } else {
        x = ((i - A[j].second) / A[j].first) + 1;
        if (s[j - 1] == '1') {
          if (x % 2 == 0) {
            tmp++;
          }
        } else {
          if (x % 2 != 0) {
            tmp++;
          }
        }
      }
    }
    ans = max(ans, tmp);
  }
  printf("%lld\n", ans);
  return 0;
}
