#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
int a[maxn], b[maxn];
int toggle[maxn];
bool on[maxn];
int main(void) {
  int n;
  while (cin >> n) {
    string s;
    cin >> s;
    queue<int> q;
    for (int i = 1; i <= n; i++) {
      cin >> a[i] >> b[i];
      toggle[i] = b[i];
      if (s[i - 1] == '1') {
        on[i] = true;
      } else {
        on[i] = false;
      }
    }
    int res = 0;
    for (int t = 0; t <= 200; t++) {
      int cur = 0;
      for (int i = 1; i <= n; i++) {
        if (t == toggle[i]) {
          on[i] = 1 - on[i];
          cur += on[i];
          toggle[i] += a[i];
        } else {
          cur += on[i];
        }
      }
      res = max(res, cur);
    }
    cout << res << endl;
  }
  return 0;
}
