#include <bits/stdc++.h>
using namespace std;
int arr[102], arr2[102];
int freq[2000];
int main() {
  int tests;
  cin >> tests;
  string s;
  cin >> s;
  for (int i = 0; i < tests; i++) {
    cin >> arr[i] >> arr2[i];
  }
  vector<int> time;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      for (int j = 0; j < arr2[i]; j++) {
        time.push_back(j);
      }
      for (int k = arr2[i] + arr[i]; k < 1000; k += arr[i] * 2) {
        for (int h = 0; h < arr[i]; h++) {
          time.push_back(h + k);
        }
      }
    } else {
      for (int j = arr2[i]; j < 1000; j += arr[i] * 2)
        for (int h = 0; h < arr[i]; h++) {
          time.push_back(h + j);
        }
    }
  }
  for (int i = 0; i < time.size(); i++) {
    freq[time[i]]++;
  }
  int maxi = 0;
  for (int i = 0; i < 1000; i++) {
    maxi = max(maxi, freq[i]);
  }
  cout << maxi;
  return 0;
}
