#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int dp[n][1001];
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    int c = 0;
    int l;
    if (s[i] == '0') {
      l = 0;
    } else {
      l = 1;
    }
    for (int j = 0; j < b; j++) dp[i][j] = l;
    l ^= 1;
    for (int j = b; j <= 1000; j++) {
      dp[i][j] = l;
      c++;
      if (c == a) {
        l ^= 1;
        c = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 1000; i++) {
    int count = 0;
    for (int j = 0; j < n; j++) {
      if (dp[j][i] == 1) count++;
    }
    if (count > ans) ans = count;
  }
  cout << ans << endl;
  return 0;
}
