#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> operator+(const pair<long long, long long> &a,
                                     const pair<long long, long long> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<long long, long long> operator-(const pair<long long, long long> &a,
                                     const pair<long long, long long> &b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<long long, long long> operator*(const pair<long long, long long> &a,
                                     const long long &b) {
  return make_pair(a.first * b, a.second * b);
}
ostream &operator<<(ostream &os, const pair<long long, long long> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
const long double PI = acos(-1);
const long long INF = (long long)(1e18) + 9;
const long double EPS = 1e-15;
const long double SEPS = 1e-6;
const long long NN = 80050;
const long long N = 1024 * 128;
const long long K = 4096;
const long long L = 26;
const unsigned long long INTF = (long long)INT_MAX * INT_MAX;
const long long LET = 26;
const long long MUL = 1000;
const long long F = 4;
long long n;
string s;
vector<long long> a, b;
vector<bool> c;
signed main() {
  double start = clock();
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(13);
  cerr << setprecision(10);
  srand(14313);
  {}
  cin >> n;
  cin >> s;
  for (long long i = 0; i < n; i++) c.push_back(s[i] == '1');
  a.resize(n);
  b.resize(n);
  for (long long i = 0; i < n; i++) cin >> a[i] >> b[i];
  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    long long cnt = 0;
    for (long long j = 0; j < n; j++) {
      if (i >= b[j] && i % a[j] == b[j] % a[j]) c[j] = c[j] ^ 1;
      if (c[j]) cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans;
  return 0;
}
