#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> a(n);
  vector<long long> b(n);
  unordered_map<int, int> mp;
  int x, y;
  for (long long i = 0; i < (n); i++) {
    cin >> x >> y;
    a[i] = x;
    b[i] = y;
  }
  int ans = 0;
  for (long long i = 0; i < (n); i++)
    if (s[i] == '1') ans += 1;
  for (int i = 1; i < 10000; i += 1) {
    for (int j = 0; j < n; j++) {
      if (i >= b[j]) {
        if ((i - b[j]) % a[j] == 0) {
          if (s[j] == '1') {
            s[j] = '0';
          } else {
            s[j] = '1';
          }
        }
      }
    }
    ans = max(ans, (int)count(s.begin(), s.end(), '1'));
  }
  cout << ans << "\n";
  return 0;
}
