#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1000;
bool s[112345][110];
int a[1100], b[1100];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = (1); i <= (n); i++) {
    char c;
    cin >> c;
    s[0][i] = c - '0';
  }
  for (int i = (1); i <= (n); i++) cin >> a[i] >> b[i];
  for (int i = (1); i <= (n); i++) {
    int cnt = 0;
    for (int j = (0); j <= (b[i] - 1); j++) s[j][i] = s[0][i];
    for (int j = b[i]; j <= 100000; j += a[i]) {
      cnt++;
      bool flag = cnt % 2;
      int siz = min(100000, j + a[i] - 1);
      for (int k = j; k <= siz; k++) {
        if (flag)
          s[k][i] = !s[0][i];
        else
          s[k][i] = s[0][i];
      }
    }
  }
  int ans = 0;
  for (int i = (0); i <= (100000); i++) {
    int now = 0;
    for (int j = (1); j <= (n); j++) now += s[i][j];
    ans = max(ans, now);
  }
  cout << ans;
  return 0;
}
