#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { return; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
void solve() {
  int N;
  cin >> N;
  string status;
  cin >> status;
  vector<vector<int>> curr;
  for (int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    vector<int> temp = {};
    if (status[i] == '1') {
      for (int i = 1; i <= 500; ++i) {
        if (i <= y)
          temp.push_back(1);
        else {
          if (((i - y + x - 1) / x) & 1) {
            temp.push_back(0);
          } else {
            temp.push_back(1);
          }
        }
      }
      curr.push_back(temp);
    } else {
      for (int i = 1; i <= 500; ++i) {
        if (i <= y)
          temp.push_back(0);
        else {
          if (((i - y + x - 1) / x) & 1) {
            temp.push_back(1);
          } else {
            temp.push_back(0);
          }
        }
      }
      curr.push_back(temp);
    }
  }
  int ret = INT_MIN;
  for (int i = 0; i < 500; ++i) {
    int cnt = 0;
    for (int j = 0; j < N; ++j) {
      if (curr[j][i] == 1) {
        ++cnt;
      }
    }
    ret = max(ret, cnt);
  }
  cout << ret << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  auto start = chrono::high_resolution_clock::now();
  solve();
  auto end = chrono::high_resolution_clock::now();
  cerr << " Execution time : "
       << chrono::duration_cast<chrono::milliseconds>(end - start).count()
       << "ms" << endl;
  return 0;
}
