#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pli = pair<long long, int>;
using pll = pair<long long, long long>;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
const int T = 130;
int ans[T];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    int flag = 0;
    if (s[i] == '0')
      flag = 0;
    else
      flag = 1;
    for (int x = 0; x < T; x++) {
      if (x >= b && (x - b) % a == 0) {
        flag ^= 1;
      }
      ans[x] += flag;
    }
  }
  int res = 0;
  for (int i = 0; i < T; i++) {
    res = max(res, ans[i]);
  }
  cout << res << "\n";
  return 0;
}
