#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, x, y, cnt = 0, mcnt = 0;
  cin >> n;
  string s;
  vector<pair<long long, long long>> v;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back(make_pair(y, x));
  }
  for (long long i = 0; i < 1000; i++) {
    cnt = 0;
    for (long long j = 0; j < n; j++) {
      if (i - v[j].first >= 0 && (i - v[j].first) % v[j].second == 0) {
        s[j] = (s[j] - '0') ^ 1 + '0';
      }
      if (s[j] == '1') cnt++;
    }
    mcnt = max(mcnt, cnt);
  }
  cout << mcnt;
  return 0;
}
