#include <bits/stdc++.h>
using namespace std;
long long ftm[105][10005];
long long ftmx[200005];
long long ltm[200005];
long long ltmx[200005];
int main() {
  ios_base::sync_with_stdio(false);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 1; i <= n; i++) {
      long long a, b;
      cin >> a >> b;
      ftm[i][b] = 1;
      for (int j = 1; j <= 500; j++) ftm[i][b + j * a] = 1;
    }
    long long x = 0;
    for (int i = 0; i <= 500; i++) {
      long long cnt = 0;
      for (int j = 0; j < n; j++) {
        if (ftm[j + 1][i] == 1) {
          if (s[j] == '0')
            s[j] = '1';
          else
            s[j] = '0';
        }
        if (s[j] == '1') cnt++;
      }
      x = max(x, cnt);
    }
    cout << x;
  }
}
