#include <bits/stdc++.h>
char con[100];
int a[100], b[100];
int n;
int main(void) {
  std::cin >> n;
  std::cin >> con;
  for (int i = 0; i != n; ++i) con[i] -= 48, std::cin >> a[i] >> b[i];
  int ans = 0;
  for (int t = 0; t <= 1000000; ++t) {
    int tans = 0;
    for (int i = 0; i != n; ++i) {
      if ((t - b[i] >= 0) && ((t - b[i]) % a[i] == 0)) con[i] ^= 1;
      if (con[i]) ++tans;
    }
    if (tans > ans) ans = tans;
  }
  std::cout << ans << std::endl;
  return 0;
}
