#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, INF = 0x3f3f3f3f, M = 1e9 + 7;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
int n, a[N], b[N], now[N];
string s;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> s;
  int ans = 0;
  for (int i = 1; i <= s.size(); i++) now[i] = s[i - 1] - '0', ans += now[i];
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  for (int i = 1; i <= N; i++) {
    int sum = 0;
    for (int j = 1; j <= n; j++) {
      if ((b[j] <= i) && ((i - b[j]) % a[j]) == 0) now[j] ^= 1;
      sum += now[j];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
