#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long int mark[10002];
int main() {
  string t;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, i, j, a, b;
  cin >> n;
  cin >> t;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    long long int f = t[i] - '0';
    for (j = 0; j < b; j++) mark[j] += f;
    for (j = b; j + a <= 10000; j += a) {
      f ^= 1;
      for (long long int k = j; k < j + a && k <= 10000; k++) mark[k] += f;
    }
  }
  long long int max1 = 0;
  for (i = 0; i <= 10000; i++) max1 = max(max1, mark[i]);
  cout << max1 << endl;
}
