#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
const int N = 1e5 + 10, M = 5000 + 5, mod = 1e9 + 7;
int ar[N];
int main() {
  fast_in_out();
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    bool f = s[i] == '1';
    for (int j = 0; j < N; j++) {
      ar[j] += f;
      ans = max(ans, ar[j]);
      if (j == v[i].second) {
        v[i].second += v[i].first;
        f = !f;
      }
    }
  }
  cout << ans;
  return 0;
}
