#include <bits/stdc++.h>
using namespace std;
const int N = 111;
int a[N], b[N], on[N];
int n;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = (1); i <= (n); i++) {
    on[i] = s[i - 1] == '1';
    ans += on[i];
  }
  for (int i = (1); i <= (n); i++) {
    cin >> a[i] >> b[i];
  }
  for (int t = (1); t <= (100000); t++) {
    int cur = 0;
    for (int i = (1); i <= (n); i++) {
      if (t >= b[i] && (t - b[i]) % a[i] == 0) {
        on[i] = 1 - on[i];
      }
      cur += on[i];
    }
    ans = max(ans, cur);
  }
  cout << ans << "\n";
  return 0;
}
