#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  map<long long, long long> mp;
  vector<long long> v[100];
  long long i, j;
  for (i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    long long f;
    if (s[i] == '1')
      f = 1;
    else
      f = 0;
    long long c = 0;
    long long temp = 0;
    long long d;
    while (temp <= 130) {
      d = b + a * c;
      for (j = temp; j < d; j++) {
        v[i].push_back(f);
      }
      if (f == 0)
        f = 1;
      else
        f = 0;
      c++;
      temp = d;
    }
    if (f == 0)
      f = 1;
    else
      f = 0;
  }
  long long mx = 0;
  for (i = 0; i <= 130; i++) {
    long long c = 0;
    for (int j = 0; j < n; j++) {
      c += v[j][i];
    }
    mx = max(c, mx);
  }
  cout << mx << endl;
}
