#include <bits/stdc++.h>
using namespace std;
long long int mini(long long int a, long long int b) {
  if (a <= b)
    return a;
  else
    return b;
}
long long int maxe(long long int a, long long int b) {
  if (a >= b)
    return a;
  else
    return b;
}
int main() {
  int n, a, b, c;
  cin >> n;
  vector<long int> v(10001);
  getchar();
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (s[i] == '1')
      c = 1;
    else
      c = 0;
    for (int j = 0; j < b; j++) {
      v[j] += c;
    }
    int ar = 0;
    for (int j = b; j <= 10000; j++) {
      if (ar == 0) c = (c + 1) % 2;
      v[j] += c;
      ar = (ar + 1) % a;
    }
  }
  long long int ans = 0;
  for (int i = 0; i < 10001; i++) {
    ans = maxe(ans, v[i]);
  }
  cout << ans;
}
