#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 1e4;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f;
int a[MAXN], b[MAXN], n, res, d[MAXN];
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '1')
      d[i] = 1;
    else
      d[i] = -1;
  }
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  for (int i = 0; i < MAXN; ++i) {
    int k = 0;
    for (int j = 0; j < n; ++j) {
      if ((i - b[j]) % a[j] == 0 && i >= b[j]) {
        d[j] = -d[j];
      }
      if (d[j] > 0) k++;
    }
    res = max(res, k);
  }
  cout << res;
  return 0;
}
