#include <bits/stdc++.h>
using namespace std;
int n, a[105], b[105], ans;
string s;
bool on[105];
int main() {
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    on[i] = s[i] - '0';
    ans += on[i];
  }
  for (int i = 1; i <= 10000; i++) {
    int cur = 0;
    for (int j = 0; j < n; j++) {
      if (i >= b[j] && (i - b[j]) % a[j] == 0) on[j] = !on[j];
      cur += on[j];
    }
    ans = max(ans, cur);
  }
  cout << ans << '\n';
}
