#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n;
int a[N], b[N];
char s[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> s + 1;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1') ++ans;
  }
  for (int i = 1; i <= 5000; i++) {
    int tmp = 0;
    for (int j = 1; j <= n; j++) {
      if (i - b[j] < 0) continue;
      int now = i - b[j];
      if (now % a[j] == 0) {
        if (s[j] == '1')
          s[j] = '0';
        else if (s[j] == '0') {
          s[j] = '1';
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      if (s[j] == '1') ++tmp;
    }
    ans = max(ans, tmp);
  }
  cout << ans;
  return 0;
}
