#include <bits/stdc++.h>
using namespace std;
long long i, j, k, n, m, p, t, c, x, z, ans, a[300007], b[300007],
    arr[110][100008];
set<long long> st;
int main() {
  string s;
  cin >> n >> s;
  for (i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (s[i] == '0')
      x = 2;
    else
      x = 1;
    for (j = b[i] - 1; j >= 0; j--) {
      arr[i][j] = x;
    }
    if (x == 1)
      x = 2;
    else
      x = 1;
    z = j = 0;
    while (1) {
      j = (a[i] * z) + b[i];
      if (j >= 100000) break;
      arr[i][j] = x;
      if (x == 1)
        x = 2;
      else
        x = 1;
      z++;
    }
    for (j = b[i] + 1; j < 100000; j++) {
      if (arr[i][j] == 0) arr[i][j] = arr[i][j - 1];
    }
  }
  for (i = 0; i < 100000; i++) {
    c = 0;
    for (j = 0; j < n; j++) {
      if (arr[j][i] == 1) c++;
    }
    ans = max(ans, c);
  }
  cout << ans << endl;
  return 0;
}
