#include <bits/stdc++.h>
using namespace std;
int n, a, b, A[100][500], ans = 0;
int main() {
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int u = 0; u < b; u++) A[i][u] = s[i] - '0';
    for (int u = b; u < 500; u++) {
      if (s[i] == '1')
        s[i] = '0';
      else
        s[i] = '1';
      for (int j = u, x = a; x > 0 && j < 500; x--, u++, j++)
        A[i][j] = s[i] - '0';
      u--;
    }
  }
  for (int i = 0; i < 500; i++) {
    int j = 0;
    for (int u = 0; u < 100; u++) j += A[u][i] == 1;
    ans = max(ans, j);
  }
  cout << ans;
  return 0;
}
