#include <bits/stdc++.h>
using namespace std;
int INF = 0x3f3f3f3f;
int n, a[105], b[105], ans, temp;
char x;
bool state[105];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == '1') {
      state[i] = 1;
      temp++;
    } else
      state[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  ans = temp;
  for (int i = 1; i <= 1000; i++) {
    temp = 0;
    for (int j = 1; j <= n; j++) {
      if (b[j] <= i) {
        if ((i - b[j]) % a[j] == 0) state[j] = (state[j] + 1) % 2;
      }
      if (state[j]) temp++;
    }
    ans = max(ans, temp);
  }
  cout << ans;
}
