#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int st[n];
  for (int i = 0; i < n; i++) {
    st[i] = (s[i] - '0');
  }
  pair<int, int> ab[n];
  for (int i = 0; i < n; i++) {
    cin >> ab[i].first >> ab[i].second;
  }
  int ans = 0;
  for (int t = 0; t <= 125; t++) {
    int cur = 0;
    for (int i = 0; i < n; i++) {
      cur += st[i];
    }
    ans = max(ans, cur);
    for (int i = 0; i < n; i++) {
      if (t == ab[i].second - 1) {
        st[i] = !st[i];
        ab[i].second += ab[i].first;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
