#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int v[maxn];
char s[maxn];
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) {
    v[i] = s[i] - '0';
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += v[i];
  }
  for (int tm = 1; tm < 100000; tm++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (tm >= b[i] && (tm - b[i]) % a[i] == 0) {
        v[i] ^= 1;
      }
      if (v[i] == 1) {
        cnt++;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
