#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int a[1000];
int b[1000];
int sec = 1;
int main() {
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    cin >> b[i] >> a[i];
  }
  int maxi = 0;
  int on = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '1') ++on;
  }
  if (on > maxi) maxi = on;
  for (int x = 0; x < 100000; ++x) {
    for (int i = 0; i < n; ++i) {
      if (sec >= a[i] && (a[i] % b[i]) == (sec % b[i])) {
        if (s[i] == '1')
          s[i] = '0';
        else
          s[i] = '1';
      }
    }
    on = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '1') ++on;
    }
    if (on > maxi) maxi = on;
    ++sec;
  }
  cout << maxi << "\n";
  return 0;
}
