#include <bits/stdc++.h>
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::fixed;
using std::ios_base;
using std::make_pair;
using std::make_tuple;
using std::map;
using std::nth_element;
using std::pair;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::stack;
using std::string;
using std::tuple;
using std::unordered_map;
using std::unordered_set;
using std::vector;
int n;
char s[105];
int t[105], a[105];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  cin >> n;
  int cm = 0;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    s[i] -= '0';
    cm += s[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> t[i];
  }
  for (int i = 1; i < 1000000; ++i) {
    int c = 0;
    for (int j = 0; j < n; ++j) {
      if (i == t[j]) {
        s[j] ^= 1;
        t[j] += a[j];
      }
      c += s[j];
    }
    cm = std::max(cm, c);
  }
  cout << cm << '\n';
  return 0;
}
