#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
long long int arr[2005][2];
long long int n, m, k, t, t1, t2, t3, t4, t5, t6;
bool state[1000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int ans = 0;
  cin >> n;
  string s;
  cin >> s;
  for (long long int i = (0); i < (n); ++i) {
    if (s[i] == '1') {
      state[i] = true;
    } else {
      state[i] = false;
    }
  }
  for (long long int i = (0); i < (n); ++i) {
    cin >> arr[i][1] >> arr[i][0];
  }
  for (long long int tt = (0); tt < (1000); ++tt) {
    for (long long int i = (0); i < (n); ++i) {
      if (tt - arr[i][0] >= 0 && (tt - arr[i][0]) % arr[i][1] == 0) {
        state[i] = !state[i];
      }
    }
    k = 0;
    for (long long int i = (0); i < (n); ++i) {
      if (state[i]) {
        k++;
      }
    }
    ans = max(ans, k);
  }
  cout << ans << endl;
  return 0;
}
