#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string init;
  cin >> init;
  vector<vector<bool>> state(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    bool cur = init[i] - '0';
    for (int j = 0; j < b; j++) {
      state[i].push_back(cur);
    }
    int cnt = 0;
    cur ^= 1;
    for (int j = 0; j < 1000 - b; j++) {
      cnt++;
      state[i].push_back(cur);
      if (cnt == a) {
        cur ^= 1;
        cnt = 0;
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < 1000; i++) {
    int on = 0;
    for (int j = 0; j < n; j++) {
      on += state[j][i];
    }
    mx = max(mx, on);
  }
  cout << mx;
}
