#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int a[107], b[107], vist[107][100007], c[107];
int main() {
  cin >> n;
  cin >> s;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      vist[i + 1][0] = 1, c[i + 1] = 1;
    else
      vist[i + 1][0] = -1, c[i + 1] = -1;
  }
  for (int i = 1; i <= n; i++) {
    int ct = 0, sum = 0;
    int v = c[i];
    int l = 1;
    while (1) {
      sum = b[i] + ct * a[i];
      if (sum > 3000) break;
      for (int j = l; j < sum; j++) vist[i][j] = v;
      vist[i][sum] = -v;
      l = sum + 1;
      ct++;
      v = -v;
    }
  }
  int ans = 0, Max = 0;
  for (int j = 0; j <= 100000; j++) {
    ans = 0;
    for (int i = 1; i <= n; i++) {
      if (vist[i][j] == 1) ans++;
    }
    Max = max(Max, ans);
  }
  cout << Max << endl;
}
