#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
bool prime[10009];
void SieveOfEratosthenes(long long n) {
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) {
        prime[i] = false;
      }
    }
  }
}
long long power(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long power1(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long mod_power(long long a, long long b, long long m) {
  long long res = 1;
  a %= m;
  while (b) {
    if (b & 1) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long printDivisors(long long n) {
  long long count = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        count++;
      else
        printf("%d %d ", i, n / i);
    }
  }
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long po[300005];
long long constants[10];
long long ab[200000];
map<pair<long long, long long>, long long> cd;
long long d, x, y;
void extendedEuclid(long long a, long long b) {
  if (b == 0) {
    d = a;
    x = 1;
    y = 0;
    extendedEuclid(b, a % b);
  } else {
    long long temp = x;
    x = y;
    y = temp - (a / b) * y;
  }
}
long long stringmod(string s, long long m) {
  long long res = 0;
  for (long long i = 0; i < s.length(); i++) {
    res = (res * 10 + (long long)s[i] - '0') % m;
  }
  return res;
}
long long fact[200005];
long long nCr(long long n, long long r) {
  long long ans = fact[n];
  ans = (ans * mod_power(fact[n - r], 1000000007 - 2, 1000000007)) % 1000000007;
  ans %= 1000000007;
  ans %= 1000000007;
  return ans;
}
bool compare(const pair<long long, string> &a,
             const pair<long long, string> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first > b.first);
}
long long min4(long long a, long long b, long long c, long long d) {
  return min(min(a, b), min(c, d));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long freq[10000] = {0};
  for (long long k = 0; k < n; k++) {
    long long a, b;
    cin >> a >> b;
    long long flag = 0;
    if (s[k] == '1') flag = 1;
    for (long long i = 0; i < b; i++) freq[i] += flag;
    for (long long i = b; i < 10000; i++) {
      if ((i - b) % a == 0) flag ^= 1;
      freq[i] += flag;
    }
  }
  long long maxi = 0;
  for (long long i = 0; i < 10000; i++) maxi = max(maxi, freq[i]);
  cout << maxi << endl;
}
