import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{       static PrintWriter out=new PrintWriter(System.out);static FastScanner in = new FastScanner(System.in);static class FastScanner {BufferedReader br;StringTokenizer stok;FastScanner(InputStream is) {br = new BufferedReader(new InputStreamReader(is));}
        String next() throws IOException {while (stok == null || !stok.hasMoreTokens()) {String s = br.readLine();if (s == null) {return null;}
                stok = new StringTokenizer(s);}return stok.nextToken();}
        int ni() throws IOException {return Integer.parseInt(next());}long nl() throws IOException {return Long.parseLong(next());}double nd() throws IOException {return Double.parseDouble(next());}char nc() throws IOException {return (char) (br.read());}String ns() throws IOException {return br.readLine();}
        int[] nia(int n) throws IOException{int a[] = new int[n];for (int i = 0; i < n; i++)a[i] = ni();return a;}long[] nla(int n) throws IOException {long a[] = new long[n];for (int i = 0; i < n; i++)a[i] = nl();return a;}
        double[] nda(int n)throws IOException {double a[] = new double[n];for (int i = 0; i < n; i++)a[i] = nd();return a;}int [][] imat(int n,int m) throws IOException{int mat[][]=new int[n][m];for(int i=0;i<n;i++){for(int j=0;j<m;j++)mat[i][j]=ni();}return mat;}
    }
	static long mod=Long.MAX_VALUE;
	public static void main (String[] args) throws java.lang.Exception
	{   int i,j;
	    HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();
		/*  if(hm.containsKey(z))
		        hm.put(z,hm.get(z)+1);
		    else
		        hm.put(z,1);
		 */
        ArrayList<Integer> arr=new ArrayList<Integer>();
        HashSet<Integer> set=new HashSet<Integer>();
        PriorityQueue<Integer> pq=new PriorityQueue<Integer>();
        int n=in.ni();
        String s=in.next();
        int a[][]=new int[n][1000];
        for(i=0;i<n;i++)
        {   int p=in.ni();
            int q=in.ni();
            if(s.charAt(i)=='1')
            {
                for(j=1;j<=q;j++)
                    a[i][j]=1;
                for(int k=1;k<=1000;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+q;j++)
                    {   if(j<1000)
                            a[i][j]=1;
                    }
                }
            }
            else
            {
                for(int k=0;k<=1000;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+q;j++)
                    {   if(j<1000)
                            a[i][j]=1;
                    }
                }
            }
        }
        int ans=0;
        for(j=0;j<=999;j++)
        {   int count=0;
            for(i=0;i<n;i++)
                if(a[i][j]==1)
                    count++;
            ans=Math.max(ans,count);
        }
        out.println(ans);

        out.close();
	}
	static class pair implements Comparable<pair>{
		int x, y;
		public pair(int x, int y){this.x = x; this.y = y;}
		@Override
		public int compareTo(pair arg0)
		{   if(x<arg0.x)    return -1;
		    else if(x==arg0.x)
		    {   if(y<arg0.y)    return -1;
		        else if(y>arg0.y)   return 1;
		        else    return 0;
		    }
		    else    return 1;
		}
	}
	static long gcd(long a,long b)
	{   if(b==0)
	        return a;
	    return gcd(b,a%b);
	}
	static long exponent(long a,long n)
	{   long ans=1;
	    while(n!=0)
	    {   if(n%2==1)
	            ans=(ans*a)%mod;
	       a=(a*a)%mod;
	       n=n>>1;
	    }
	    return ans;
	}
	static int binarySearch(int a[], int item, int low, int high)
    {   if (high <= low)
            return (item > a[low])?  (low + 1): low;
        int mid = (low + high)/2;
        if(item == a[mid])
            return mid+1;
        if(item > a[mid])
            return binarySearch(a, item, mid+1, high);
        return binarySearch(a, item, low, mid-1);
    }
    static void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2];

        for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) {   if (L[i] <= R[j]) {   arr[k] = L[i]; i++; } else{   arr[k] = R[j]; j++; } k++; } while (i < n1){   arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j];   j++;     k++; }
    }
    static void Sort(int arr[], int l, int r) {if (l < r) {   int m = (l+r)/2; Sort(arr, l, m); Sort(arr , m+1, r); merge(arr, l, m, r); } }

    static void sort(int a[])
    {Sort(a,0,a.length-1);}
}


import java.util.Arrays;
import java.util.Scanner;

public class TestCase{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int tc = sc.nextInt();
		String str = sc.next();
		int[] time = new int[1001];
		int in = 0;
		int light = 0;
		while(tc-->0) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(str.charAt(in)=='1') light = 1;
			else light = 0;
			in++;
			int check = b;
			int cnt = 0;
			for(int i=0;i<1001;i++) {
				if(i == check) {
					if(light == 0) light = 1;
					else light = 0;
					cnt++;
				}
				if(light == 1) time[i]++;
				check = a*cnt+b;
			//	System.out.print(time[i]+" ");
			}
			//System.out.println();
		}
		int max = 0;
		for(int i=0; i<1001; i++) {
			if(time[i]>max) max = time[i];
		}
		System.out.println(max);
		sc.close();
	}
}


import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class B {

	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner(System.in);
		FastPrinter out = new FastPrinter(System.out);
		new B().run(sc, out);
		out.close();
	}

	final int MAXN = 100_000;

	public void run(FastScanner sc, FastPrinter out) throws Exception {
		int N = sc.nextInt();
		char[] init = sc.next().toCharArray();
		int[][] arr = new int[N][];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextIntArray(2);
		}
		int ans = 0;

		for (int t = 0; t < MAXN; t++) {
			int temp = 0;
			for (int i = 0; i < N; i++) {
				if (t >= arr[i][1]) {
					if ((t - arr[i][1]) % arr[i][0] == 0) {
						if (init[i] == '1') {
							init[i] = '0';
						} else {
							init[i] = '1';
						}
					}
				}
				if (init[i] == '1') {
					temp++;
				}
			}
			if (temp > ans) ans = temp;
		}
		out.println(ans);
	}

	public void shuffle(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			int r = (int) (Math.random() * arr.length);
			if (i != r) {
				arr[i] ^= arr[r];
				arr[r] ^= arr[i];
				arr[i] ^= arr[r];
			}
		}
	}

	static class FastScanner {
		final private int BUFFER_SIZE = 1 << 10;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream stream) {
			din = new DataInputStream(stream);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public FastScanner(String fileName) throws IOException {
			Path p = Paths.get(fileName);
			buffer = Files.readAllBytes(p);
			bytesRead = buffer.length;
		}

		int[] nextIntArray(int N) throws IOException {
			int[] arr = new int[N];
			for (int i = 0; i < N; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		String nextLine() throws IOException {
			int c = read();
			while (c != -1 && isEndline(c))
				c = read();
			if (c == -1) {
				return null;
			}
			StringBuilder res = new StringBuilder();
			do {
				if (c >= 0) {
					res.appendCodePoint(c);
				}
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		String next() throws Exception {
			int c = readOutSpaces();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg) c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg) return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg) c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg) return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg) c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg) return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			if (din == null) {
				bufferPointer = 0;
				bytesRead = -1;
			} else {
				bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			}
			if (bytesRead == -1) buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead) fillBuffer();
			return buffer[bufferPointer++];
		}

		private int readOutSpaces() throws IOException {
			while (true) {
				if (bufferPointer == bytesRead) fillBuffer();
				int c = buffer[bufferPointer++];
				if (!isSpaceChar(c)) {
					return c;
				}
			}
		}

		public void close() throws IOException {
			if (din == null) return;
			din.close();
		}

		public int[][] readGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][] adj = new int[N][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][2];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				input[i][0] = a;
				input[i][1] = b;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				adj[a][numNodes[a]++] = b;
				if (bidirectional) adj[b][numNodes[b]++] = a;
			}
			return adj;
		}

		public int[][][] readWeightedGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][][] adj = new int[N][][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][3];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				int d = nextInt();
				input[i][0] = a;
				input[i][1] = b;
				input[i][2] = d;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]][2];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				int d = input[i][2];
				adj[a][numNodes[a]][0] = b;
				adj[a][numNodes[a]][1] = d;
				numNodes[a]++;
				if (bidirectional) {
					adj[b][numNodes[b]][0] = a;
					adj[b][numNodes[b]][1] = d;
					numNodes[b]++;
				}
			}
			return adj;
		}
	}

	static class FastPrinter {
		static final char ENDL = '\n';
		StringBuilder buf;
		PrintWriter pw;

		public FastPrinter(OutputStream stream) {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
		}

		public FastPrinter(String fileName) throws Exception {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
		}

		public FastPrinter(StringBuilder buf) {
			this.buf = buf;
		}

		public void print(int a) {
			buf.append(a);
		}

		public void print(long a) {
			buf.append(a);
		}

		public void print(char a) {
			buf.append(a);
		}

		public void print(char[] a) {
			buf.append(a);
		}

		public void print(double a) {
			buf.append(a);
		}

		public void print(String a) {
			buf.append(a);
		}

		public void print(Object a) {
			buf.append(a.toString());
		}

		public void println() {
			buf.append(ENDL);
		}

		public void println(int a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(long a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char[] a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(double a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(String a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(Object a) {
			buf.append(a.toString());
			buf.append(ENDL);
		}

		public void printf(String format, Object... args) {
			buf.append(String.format(format, args));
		}

		public void close() {
			pw.print(buf);
			pw.close();
		}

		public void flush() {
			pw.print(buf);
			pw.flush();
			buf.setLength(0);
		}

	}

}


import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class B {

	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner(System.in);
		FastPrinter out = new FastPrinter(System.out);
		new B().run(sc, out);
		out.close();
	}

	final int MAXN = 1_000_000;

	public void run(FastScanner sc, FastPrinter out) throws Exception {
		int N = sc.nextInt();
		char[] init = sc.next().toCharArray();
		int[][] arr = new int[N][];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextIntArray(2);
		}
		int ans = 0;

		for (int t = 0; t < MAXN; t++) {
			int temp = 0;
			for (int i = 0; i < N; i++) {
				if (t >= arr[i][1]) {
					if ((t - arr[i][1]) % arr[i][0] == 0) {
						if (init[i] == '1') {
							init[i] = '0';
						} else {
							init[i] = '1';
						}
					}
				}
				if (init[i] == '1') {
					temp++;
				}
			}
			if (temp > ans) ans = temp;
		}
		System.out.println(ans);
	}

	public void shuffle(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			int r = (int) (Math.random() * arr.length);
			if (i != r) {
				arr[i] ^= arr[r];
				arr[r] ^= arr[i];
				arr[i] ^= arr[r];
			}
		}
	}

	static class FastScanner {
		final private int BUFFER_SIZE = 1 << 10;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream stream) {
			din = new DataInputStream(stream);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public FastScanner(String fileName) throws IOException {
			Path p = Paths.get(fileName);
			buffer = Files.readAllBytes(p);
			bytesRead = buffer.length;
		}

		int[] nextIntArray(int N) throws IOException {
			int[] arr = new int[N];
			for (int i = 0; i < N; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		String nextLine() throws IOException {
			int c = read();
			while (c != -1 && isEndline(c))
				c = read();
			if (c == -1) {
				return null;
			}
			StringBuilder res = new StringBuilder();
			do {
				if (c >= 0) {
					res.appendCodePoint(c);
				}
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		String next() throws Exception {
			int c = readOutSpaces();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg) c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg) return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg) c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg) return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg) c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg) return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			if (din == null) {
				bufferPointer = 0;
				bytesRead = -1;
			} else {
				bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			}
			if (bytesRead == -1) buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead) fillBuffer();
			return buffer[bufferPointer++];
		}

		private int readOutSpaces() throws IOException {
			while (true) {
				if (bufferPointer == bytesRead) fillBuffer();
				int c = buffer[bufferPointer++];
				if (!isSpaceChar(c)) {
					return c;
				}
			}
		}

		public void close() throws IOException {
			if (din == null) return;
			din.close();
		}

		public int[][] readGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][] adj = new int[N][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][2];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				input[i][0] = a;
				input[i][1] = b;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				adj[a][numNodes[a]++] = b;
				if (bidirectional) adj[b][numNodes[b]++] = a;
			}
			return adj;
		}

		public int[][][] readWeightedGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][][] adj = new int[N][][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][3];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				int d = nextInt();
				input[i][0] = a;
				input[i][1] = b;
				input[i][2] = d;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]][2];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				int d = input[i][2];
				adj[a][numNodes[a]][0] = b;
				adj[a][numNodes[a]][1] = d;
				numNodes[a]++;
				if (bidirectional) {
					adj[b][numNodes[b]][0] = a;
					adj[b][numNodes[b]][1] = d;
					numNodes[b]++;
				}
			}
			return adj;
		}
	}

	static class FastPrinter {
		static final char ENDL = '\n';
		StringBuilder buf;
		PrintWriter pw;

		public FastPrinter(OutputStream stream) {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
		}

		public FastPrinter(String fileName) throws Exception {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
		}

		public FastPrinter(StringBuilder buf) {
			this.buf = buf;
		}

		public void print(int a) {
			buf.append(a);
		}

		public void print(long a) {
			buf.append(a);
		}

		public void print(char a) {
			buf.append(a);
		}

		public void print(char[] a) {
			buf.append(a);
		}

		public void print(double a) {
			buf.append(a);
		}

		public void print(String a) {
			buf.append(a);
		}

		public void print(Object a) {
			buf.append(a.toString());
		}

		public void println() {
			buf.append(ENDL);
		}

		public void println(int a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(long a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char[] a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(double a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(String a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(Object a) {
			buf.append(a.toString());
			buf.append(ENDL);
		}

		public void printf(String format, Object... args) {
			buf.append(String.format(format, args));
		}

		public void close() {
			pw.print(buf);
			pw.close();
		}

		public void flush() {
			pw.print(buf);
			pw.flush();
			buf.setLength(0);
		}

	}

}


import java.util.*;
import java.io.*;

public class B {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        boolean[] on = new boolean[n];
        char[] line = scanner.next().toCharArray();
        for(int i = 0; i < n; i++) {
            on[i] = (line[i] == '1');
        }
        for(int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 0; i < n; i++) {
            if (on[i]) ans++;
        }
        for(int i = 1; i <= 10000; i++) {
            int cnt = 0;
            for(int j = 0; j < n; j++) {
                if ((i-b[j]) % a[j] == 0) {
                    on[j] = !on[j];
                }
                if (on[j]) cnt++;
            }
            ans = Math.max(ans, cnt);
        }
        out.println(ans);
        out.flush();
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class B {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        boolean[] on = new boolean[n];
        char[] line = scanner.next().toCharArray();
        for(int i = 0; i < n; i++) {
            on[i] = line[i] == '1';
        }
        for(int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i <= 1000; i++) {
            int cnt = 0;
            for(int j = 0; j < n; j++) {
                if ((i-b[j]) % a[j] == 0) {
                    if (on[j]) on[j] = false;
                    else {
                        on[j] = true;
                    }
                }
                if (on[j]) cnt++;
            }
            ans  = Math.max(ans, cnt);
        }
        out.println(ans);
        out.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class B {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        boolean[] on = new boolean[n];
        char[] line = scanner.next().toCharArray();
        for(int i = 0; i < n; i++) {
            on[i] = (line[i] == '1');
        }
        for(int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 0; i <= 10000; i++) {
            int cnt = 0;
            for(int j = 0; j < n; j++) {
                if (i >= b[j] && (i-b[j]) % a[j] == 0) {
                    on[j] = !on[j];
                }
                if (on[j]) cnt++;
            }
            ans = Math.max(ans, cnt);
        }
        out.println(ans);
        out.flush();
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class B {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        boolean[] on = new boolean[n];
        char[] line = scanner.next().toCharArray();
        for(int i = 0; i < n; i++) {
            on[i] = line[i] == '1';
        }
        for(int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 0; i < n; i++) {
            if (on[i]) ans++;
        }
        for(int i = 1; i <= 2200; i++) {
            int cnt = 0;
            for(int j = 0; j < n; j++) {
                if ((i-b[j]) % a[j] == 0) {
                    on[j] = !on[j];
                }
                if (on[j]) cnt++;
            }
            ans = Math.max(ans, cnt);
        }
        out.println(ans);
        out.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Solution(),"Main",1<<27).start();
	}

	public static long gcd(long a, long b)
	{
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static long findGCD(long arr[], int n)
	{
		long result = arr[0];
		for (int i = 1; i < n; i++)
			result = gcd(arr[i], result);
		return result;
	}

	static void sortbycolomn(long arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<long[]>() {

          @Override

          public int compare(final long[] entry1,
                             final long[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }

	public void run()
	{
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		int n=in.nextInt();
		String s=in.next();
		char[] c=s.toCharArray();
	    int[] p=new int[n];
	    int[] st=new int[n];
	    int[] temp=new int[n];
	    for(int i=0;i<n;i++){
	        p[i]=in.nextInt();
	        st[i]=in.nextInt();
	        temp[i]=p[i];
	    }
	    int flag=0;
	    int count=0;
	    for(int i=0;i<n;i++) if(c[i]=='1') count++;
	    int tc=0;
	    for(int i=1;i<=1000;i++){
	        tc=0;
	        for(int j=0;j<n;j++){
	            if(st[j]==1){
	                st[j]=0;
	                c[j]=(c[j]=='0'?'1':'0');
	                temp[j]--;
	            }
	            else if(st[j]==0){
	                if(temp[j]==0){
	                    c[j]=(c[j]=='0'?'1':'0');
	                    temp[j]=p[j]-1;
	                }
	                else
	                    temp[j]--;
	            }
	            else{
	                st[j]--;
	                flag=1;
	            }

	            if(c[j]=='1')
	                tc++;
	        }
	        count=Math.max(count,tc);
	        if(count==n)
	            break;
	    }
	    w.println(count);
		w.flush();
		w.close();
	}
}


import java.util.*;
import java.math.*;

// **** B. Koala and Lights ****

public class B {
	static char [] in = new char [1000000];
	public static void main (String [] arg) throws Throwable {
		int n = nextInt();
		char [] s = next().toCharArray();
		Pair [] L = new Pair [n];

		for (int i = 0; i<n; ++i) {
			int ai = nextInt();
			int bi = nextInt();
			L[i] = new Pair(ai, bi, i);
		}
		int on = 0;
		for (int j = 0; j<s.length; ++j) if (s[j] == '1') on++;
		int max = on;
		for (int step = 1; step<10000; ++step) {
			for (int j = 0; j<n; ++j) {
				if (step == L[j].j || step > L[j].j && (step-L[j].j) % L[j].i == 0) {
					boolean onNow = s[j] == '1';
					s[j] = (onNow) ? '0' : '1';
					on += (onNow) ? -1 : 1;
				}
			}
			max = Math.max(on, max);
		}
		System.out.println(max);
	}

	/************** HELPER CLASSES ***************/
    //static class HS extends HashSet<Integer>{public HS(){super();}public HS(int a){super(a);}};
	//static class AL extends ArrayList<Integer>{public AL(){super();}public AL(int a){super (a);}};
	static class Pair implements Comparable<Pair> {
		int i,j;long L; public Pair(int xx, int yy, long LL){i=xx;j=yy;L=LL;}
		public int compareTo(Pair p) { return (this.L < p.L) ? -1 : (this.L == p.L) ? this.i - p.i : 1;}
	}
	/************** FAST IO CODE FOLLOWS *****************/
	public static long nextLong() throws Throwable {
		long i = System.in.read();boolean neg = false;while (i < 33) i = System.in.read();if (i == 45) {neg=true;i=48;}i = i - 48;
		int j = System.in.read();while (j > 32) {i*=10;i+=j-48;j = System.in.read();}return (neg) ? -i : i;
	}
	public static int nextInt() throws Throwable {return (int)nextLong();}
	public static String next() throws Throwable {
		int i = 0; while (i < 33 && i != -1) i = System.in.read(); int cptr = 0; while (i >= 33) { in[cptr++] = (char)i; i = System.in.read();}
		return new String(in, 0,cptr);
	}
	/**** LIBRARIES ****/
	public static long gcdL(long a, long b) {while (b != 0) {long tmp = b;b = (a % b);a = tmp;}return a;}
	public static int gcd(int a, int b) {while (b != 0) {int tmp = b;b = (a % b);a = tmp;}return a;}
	public static int[] sieve(int LIM) {
		int i,count = 0;
		boolean [] b = new boolean [LIM];
		for (i = 2;i<LIM; ++i) if (!b[i]) {count++; for (int j = i<<1; j<LIM; j+=i) b[j] = true;}
		int [] primes = new int[count];
		for (i = 2,count=0;i<LIM;++i) if (!b[i]) primes[count++] = i;
		return primes;
	}
	public static int[] numPrimeFactors(int LIM) {
		int i,count = 0;
		int [] b = new int [LIM];
		for (i = 2;i<LIM; ++i) if (b[i] == 0) {count++; for (int j = i; j<LIM; j+=i) b[j]++;}
		return b;
	}
	public static StringBuilder stringFromArray(int [] a) {
		StringBuilder b = new StringBuilder(9*a.length);
		for (int i = 0; i<a.length; ++i) {
			if (i != 0) b = b.append(' ');
			b = b.append(a[i]);
		}
		return b;
	}
	public static long modPow (long a, long n, long MOD) { long S = 1; for (;n > 0; n>>=1, a=(a*a)%MOD) if ((n & 1) != 0) S = (a*S) % MOD; return S;}
}

/* Full Problem Text:

It is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of which flash periodically.
After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters a_i and b_i.
Light with parameters a_i and b_i will toggle (on to off, or off to on) every a_i seconds starting from the b_i-th second.
In other words, it will toggle at the moments b_i, b_i + a_i, b_i + 2 \cdot a_i and so on.
You know for each light whether it's initially on or off and its corresponding parameters a_i and b_i.
Koala is wondering what is the maximum number of lights that will ever be on at the same time.
So you need to find that out.
Here is a graphic for the first example.
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class KoalaAndLights {
    static int[][] lamp = new int[100][2];
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(f.readLine());
        char[] s = f.readLine().toCharArray();
        StringTokenizer st;
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(f.readLine());
            lamp[i][0] = Integer.parseInt(st.nextToken());
            lamp[i][1] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for (int time = 0; time < 100000; time++) {
            int curRes = 0;
            for (int i = 0; i < N; i++) {
                if (lamp[i][1] <= time) {
                    if (((time - lamp[i][1]) / lamp[i][0]) % 2 == 0) {
                        if (s[i] == '1') {
                            curRes++;
                        }
                    } else {
                        if (s[i] == '0') {
                            curRes++;
                        }
                    }
                }
            }
            ans = Math.max(curRes, ans);
        }
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class KoalaAndLights {
    static int[][] lamp = new int[100][2];
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(f.readLine());
        char[] s = f.readLine().toCharArray();
        StringTokenizer st;
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(f.readLine());
            lamp[i][0] = Integer.parseInt(st.nextToken());
            lamp[i][1] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for (int time = 0; time < 1000; time++) {
            int curRes = 0;
            for (int i = 0; i < N; i++) {
                if (((time - lamp[i][1])/lamp[i][0])%2 == 0) {
                    if (s[i] == '1') {
                        curRes++;
                    }
                }
                else {
                    if (s[i] == '0') {
                        curRes++;
                    }
                }
            }
            ans = Math.max(curRes, ans);
        }
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class KoalaAndLights {
    static int[][] lamp = new int[100][2];
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(f.readLine());
        char[] s = f.readLine().toCharArray();
        StringTokenizer st;
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(f.readLine());
            lamp[i][0] = Integer.parseInt(st.nextToken());
            lamp[i][1] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for (int time = 0; time < 100000; time++) {
            int curRes = 0;
            for (int i = 0; i < N; i++) {
                if (lamp[i][1] <= time) {
                    if (((time - lamp[i][1]) / lamp[i][0]) % 2 == 0) {
                        if (s[i] == '0') {
                            curRes++;
                        }
                    } else {
                        if (s[i] == '1') {
                            curRes++;
                        }
                    }
                }
                else {
                    if (s[i] == '1') {
                        curRes++;
                    }
                }
            }
            ans = Math.max(curRes, ans);
        }
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class KoalaAndLights {
    static int[][] lamp = new int[100][2];
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(f.readLine());
        char[] s = f.readLine().toCharArray();
        StringTokenizer st;
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(f.readLine());
            lamp[i][0] = Integer.parseInt(st.nextToken());
            lamp[i][1] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for (int time = 0; time < 100000; time++) {
            int curRes = 0;
            for (int i = 0; i < N; i++) {
                if (lamp[i][1] <= time) {
                    if (((time - lamp[i][1]) / lamp[i][0]) % 2 == 0) {
                        if (s[i] == '1') {
                            curRes++;
                        }
                    } else {
                        if (s[i] == '0') {
                            curRes++;
                        }
                    }
                }
                else {
                    if (s[i] == '1') {
                        curRes++;
                    }
                }
            }
            ans = Math.max(curRes, ans);
        }
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class KoalaAndLights {
    static int[][] lamp = new int[100][2];
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(f.readLine());
        char[] s = f.readLine().toCharArray();
        StringTokenizer st;
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(f.readLine());
            lamp[i][0] = Integer.parseInt(st.nextToken());
            lamp[i][1] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for (int time = 0; time < 100000; time++) {
            int curRes = 0;
            for (int i = 0; i < N; i++) {
                if (lamp[i][1] >= time) {
                    if (((time - lamp[i][1]) / lamp[i][0]) % 2 == 0) {
                        if (s[i] == '1') {
                            curRes++;
                        }
                    } else {
                        if (s[i] == '0') {
                            curRes++;
                        }
                    }
                }
            }
            ans = Math.max(curRes, ans);
        }
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class KoalaAndLights {
    static int[][] lamp = new int[100][2];
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(f.readLine());
        char[] s = f.readLine().toCharArray();
        StringTokenizer st;
        for (int i = 0; i < N; i++) {
            st = new StringTokenizer(f.readLine());
            lamp[i][0] = Integer.parseInt(st.nextToken());
            lamp[i][1] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for (int time = 0; time < 100000; time++) {
            int curRes = 0;
            for (int i = 0; i < N; i++) {
                if (((time - lamp[i][1])/lamp[i][0])%2 == 0) {
                    if (s[i] == '1') {
                        curRes++;
                    }
                }
                else {
                    if (s[i] == '0') {
                        curRes++;
                    }
                }
            }
            ans = Math.max(curRes, ans);
        }
        System.out.println(ans);
    }
}


import java.util.*;
import java.io.*;

public class A1 {

	public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public static Integer nextInt() {
        return Integer.parseInt(next());
    }

    public static Long nextLong() {
        return Long.parseLong(next());
    }

    public static Double nextDouble() {
        return Double.parseDouble(next());
    }

    static long fast_pow(long base,long n,long M)
    {
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }

    static long finextDoubleMMI_fermat(long n,int M)
    {
        return fast_pow(n,M-2,M);
    }

    static long nCrModPFermat(int n, int r, int p)
    {
        if (r == 0)
            return 1;
        long[] fac = new long[n+1];
        fac[0] = 1;
        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;
        return (fac[n]* finextDoubleMMI_fermat(fac[r], p)% p * finextDoubleMMI_fermat(fac[n-r], p) % p) % p;
    }

    static void merge(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;

        int L[] = new int [n1];
        int R[] = new int [n2];

        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;

        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static void sort(int arr[])
    {
        int l=0;
        int r=arr.length-1;
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static long gcd(long a, long b){
        if(a%b==0)
            return b;
        if(b%a==0)
            return a;
        if(a>b)
            return gcd(a%b,b);
        return gcd(a,b%a);
    }

    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String args[])throws IOException{
    	int i,j;
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=nextInt();
        String s=next();
        int a[]=new int[n];
        int b[]=new int[n];
        for(i=0;i<n;i++){
            a[i]=nextInt();
            b[i]=nextInt();
        }
        int y[]=new int[n];
        int u=0,max=0;
        for(i=0;i<n;i++){
            y[i]=s.charAt(i)-48;
            u+=y[i];
        }
        max=Math.max(u,max);
        for(i=1;i<=500;i++){
            u=0;
            for(j=0;j<n;j++){
                if((i-a[j]+b[j])%b[j]==0){
                    y[j]=y[j]^1;
                }
                u+=y[j];
            }
            max=Math.max(u,max);
        }
        pw.println(max);
        pw.close();
    }
}


import java.util.*;
import java.io.*;

public class A1 {

	public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public static Integer nextInt() {
        return Integer.parseInt(next());
    }

    public static Long nextLong() {
        return Long.parseLong(next());
    }

    public static Double nextDouble() {
        return Double.parseDouble(next());
    }

    static long fast_pow(long base,long n,long M)
    {
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }

    static long finextDoubleMMI_fermat(long n,int M)
    {
        return fast_pow(n,M-2,M);
    }

    static long nCrModPFermat(int n, int r, int p)
    {
        if (r == 0)
            return 1;
        long[] fac = new long[n+1];
        fac[0] = 1;
        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;
        return (fac[n]* finextDoubleMMI_fermat(fac[r], p)% p * finextDoubleMMI_fermat(fac[n-r], p) % p) % p;
    }

    static void merge(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;

        int L[] = new int [n1];
        int R[] = new int [n2];

        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;

        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static void sort(int arr[])
    {
        int l=0;
        int r=arr.length-1;
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static long gcd(long a, long b){
        if(a%b==0)
            return b;
        if(b%a==0)
            return a;
        if(a>b)
            return gcd(a%b,b);
        return gcd(a,b%a);
    }

    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String args[])throws IOException{
    	int i,j;
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=nextInt();
        String s=next();
        int a[]=new int[n];
        int b[]=new int[n];
        for(i=0;i<n;i++){
            a[i]=nextInt();
            b[i]=nextInt();
        }
        int y[]=new int[n];
        int u=0,max=0;
        for(i=0;i<n;i++){
            y[i]=s.charAt(i)-48;
            u+=y[i];
        }
        max=Math.max(u,max);
        for(i=1;i<=500;i++){
            u=0;
            for(j=0;j<n;j++){
                y[j]=1^(((i-a[j]+b[j])%b[j]==0)?1:0);
                u+=y[j];
            }
            max=Math.max(u,max);
        }
        pw.println(max);
        pw.close();
    }
}


import java.util.*;
import java.io.*;

public class A1 {

	public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public static Integer nextInt() {
        return Integer.parseInt(next());
    }

    public static Long nextLong() {
        return Long.parseLong(next());
    }

    public static Double nextDouble() {
        return Double.parseDouble(next());
    }

    static long fast_pow(long base,long n,long M)
    {
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }

    static long finextDoubleMMI_fermat(long n,int M)
    {
        return fast_pow(n,M-2,M);
    }

    static long nCrModPFermat(int n, int r, int p)
    {
        if (r == 0)
            return 1;
        long[] fac = new long[n+1];
        fac[0] = 1;
        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;
        return (fac[n]* finextDoubleMMI_fermat(fac[r], p)% p * finextDoubleMMI_fermat(fac[n-r], p) % p) % p;
    }

    static void merge(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;

        int L[] = new int [n1];
        int R[] = new int [n2];

        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;

        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static void sort(int arr[])
    {
        int l=0;
        int r=arr.length-1;
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static long gcd(long a, long b){
        if(a%b==0)
            return b;
        if(b%a==0)
            return a;
        if(a>b)
            return gcd(a%b,b);
        return gcd(a,b%a);
    }

    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String args[])throws IOException{
    	int i,j;
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=nextInt();
        String s=next();
        int a[]=new int[n];
        int b[]=new int[n];
        for(i=0;i<n;i++){
            a[i]=nextInt();
            b[i]=nextInt();
        }
        int y[]=new int[n];
        int u=0,max=0;
        for(i=0;i<n;i++){
            y[i]=s.charAt(i)-48;
            u+=y[i];
        }
        max=Math.max(u,max);
        for(i=1;i<=100;i++){
            u=0;
            for(j=0;j<n;j++){
                y[j]=1^(((i-a[j])%b[j]==0)?1:0);
                u+=y[j];
            }
            max=Math.max(u,max);
        }
        pw.println(max);
        pw.close();
    }
}


import java.util.*;
import java.io.*;

public class A1 {

	public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public static Integer nextInt() {
        return Integer.parseInt(next());
    }

    public static Long nextLong() {
        return Long.parseLong(next());
    }

    public static Double nextDouble() {
        return Double.parseDouble(next());
    }

    static long fast_pow(long base,long n,long M)
    {
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }

    static long finextDoubleMMI_fermat(long n,int M)
    {
        return fast_pow(n,M-2,M);
    }

    static long nCrModPFermat(int n, int r, int p)
    {
        if (r == 0)
            return 1;
        long[] fac = new long[n+1];
        fac[0] = 1;
        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;
        return (fac[n]* finextDoubleMMI_fermat(fac[r], p)% p * finextDoubleMMI_fermat(fac[n-r], p) % p) % p;
    }

    static void merge(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;

        int L[] = new int [n1];
        int R[] = new int [n2];

        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;

        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static void sort(int arr[])
    {
        int l=0;
        int r=arr.length-1;
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static long gcd(long a, long b){
        if(a%b==0)
            return b;
        if(b%a==0)
            return a;
        if(a>b)
            return gcd(a%b,b);
        return gcd(a,b%a);
    }

    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String args[])throws IOException{
    	int i,j;
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=nextInt();
        String s=next();
        int a[]=new int[n];
        int b[]=new int[n];
        for(i=0;i<n;i++){
            a[i]=nextInt();
            b[i]=nextInt();
        }
        int y[]=new int[n];
        int u=0,max=0;
        for(i=0;i<n;i++){
            y[i]=s.charAt(i)-48;
            u+=y[i];
        }
        max=Math.max(u,max);
        for(i=1;i<=500;i++){
            u=0;
            for(j=0;j<n;j++){
                if(i>=b[j]&&(i-b[j]+5*a[j])%a[j]==0){
                    y[j]=y[j]^1;
                }
                u+=y[j];
            }
            max=Math.max(u,max);
        }
        pw.println(max);
        pw.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main2 {

    static long mod = 998244353;
    static FastScanner scanner;

    static Set<Long> second = new HashSet<>();
    static boolean applied = false;

    public static void main(String[] args) {
        scanner = new FastScanner();
        int n = scanner.nextInt();
        char[] s = scanner.nextLine().toCharArray();

        int[] counter = new int[1000000];
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int state = s[i] - '0';
            for (int j = 0; j < b; j++) {
                counter[j] += state;
            }
            for (int j = 0; j + b < counter.length; j++) {
                if (j % a == 0) {
                    state = (state + 1) % 2;
                }
                counter[j + b] += state;
            }
        }
        int max = 0;
        for (int i = 0; i < counter.length; i++) max = Math.max(max, counter[i]);
        System.out.println(max);
    }

    static class WithIdx implements Comparable<WithIdx>{
        int val, idx;

        public WithIdx(int val, int idx) {
            this.val = val;
            this.idx = idx;
        }

        @Override
        public int compareTo(WithIdx o) {
            return Integer.compare(val, o.val);
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) res[i] = nextInt();
            return res;
        }

        long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) res[i] = nextLong();
            return res;
        }

        String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) res[i] = nextToken();
            return res;
        }
    }

    static class PrefixSums {
        long[] sums;

        public PrefixSums(long[] sums) {
            this.sums = sums;
        }

        public long sum(int fromInclusive, int toExclusive) {
            if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value");
            return sums[toExclusive] - sums[fromInclusive];
        }

        public static PrefixSums of(int[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }

        public static PrefixSums of(long[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }
    }

    static class ADUtils {
        static void sort(int[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                int a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }

        static void reverse(int[] arr) {
            int last = arr.length / 2;
            for (int i = 0; i < last; i++) {
                int tmp = arr[i];
                arr[i] = arr[arr.length - 1 - i];
                arr[arr.length - 1 - i] = tmp;
            }
        }

        static void sort(long[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                long a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }
    }

    static class MathUtils {
        static long[] FIRST_PRIMES = {
                2,     3,      5,      7,     11,     13,     17,     19,     23,     29,
                31,     37,     41,     43,     47,     53,     59,     61,     67,     71,
                73,     79,     83,     89  ,   97 ,    101,    103,    107,    109,    113,
                127,    131,    137,    139,    149,    151,    157,    163,    167,    173,
                179,    181,    191,    193,    197,    199,    211,    223,    227,    229,
                233,    239,    241,    251,    257,    263,    269,    271,    277,    281,
                283,    293,    307,    311,    313,    317,    331,    337,    347,    349,
                353,    359,    367,    373,    379,    383,    389,    397,    401,    409,
                419,    421,    431,    433,    439,    443,    449,    457,    461,    463,
                467,    479,    487,    491,    499,    503,    509,    521,    523,    541,
                547,    557,    563,    569,    571,    577,    587,    593,    599,    601,
                607,    613,    617,    619,    631,    641,    643,    647,    653,    659,
                661,    673,    677,    683,    691,    701,    709,    719,    727,    733,
                739,    743,    751,    757,    761,    769,    773,    787,    797,    809,
                811,    821,    823,    827,    829,    839,    853,    857,    859,    863,
                877,    881,    883,    887,    907,    911,    919,    929,    937,    941,
                947,    953,    967,    971,    977,    983,    991,    997,   1009,   1013,
                1019,   1021,   1031,   1033,   1039,   1049,   1051};

        static long[] primes(int to) {
            long[] all = new long[to + 1];
            long[] primes = new long[to + 1];
            all[1] = 1;
            int primesLength = 0;
            for (int i = 2; i <= to; i ++) {
                if (all[i] == 0) {
                    primes[primesLength++] = i;
                    all[i] = i;
                }
                for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) {
                    all[(int) (i * primes[j])] = primes[j];
                }
            }
            return Arrays.copyOf(primes, primesLength);
        }

        static long modpow(long b, long e, long m) {
            long result = 1;

            while (e > 0) {
                if ((e & 1) == 1) {
                    /* multiply in this bit's contribution while using modulus to keep
                     * result small */
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                e >>= 1;
            }

            return result;
        }

        static long submod(long x, long y, long m) {
            return (x - y + m) % m;
        }
    }
}

/*

 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main2 {

    static long mod = 998244353;
    static FastScanner scanner;

    static Set<Long> second = new HashSet<>();
    static boolean applied = false;

    public static void main(String[] args) {
        scanner = new FastScanner();
        int n = scanner.nextInt();
        char[] s = scanner.nextLine().toCharArray();

        int[] counter = new int[1000000];
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int state = s[i] - '0';
            for (int j = 0; j < b; j++) {
                counter[j] += state;
            }
            state = (state + 1) % 2;
            for (int j = 0; j + b < counter.length; j++) {
                if (j % a == 0) {
                    state = (state + 1) % 2;
                }
                counter[j + b] += state;
            }
        }
        int max = 0;
        for (int i = 0; i < counter.length; i++) max = Math.max(max, counter[i]);
        System.out.println(max);
    }

    static class WithIdx implements Comparable<WithIdx>{
        int val, idx;

        public WithIdx(int val, int idx) {
            this.val = val;
            this.idx = idx;
        }

        @Override
        public int compareTo(WithIdx o) {
            return Integer.compare(val, o.val);
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) res[i] = nextInt();
            return res;
        }

        long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) res[i] = nextLong();
            return res;
        }

        String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) res[i] = nextToken();
            return res;
        }
    }

    static class PrefixSums {
        long[] sums;

        public PrefixSums(long[] sums) {
            this.sums = sums;
        }

        public long sum(int fromInclusive, int toExclusive) {
            if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value");
            return sums[toExclusive] - sums[fromInclusive];
        }

        public static PrefixSums of(int[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }

        public static PrefixSums of(long[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }
    }

    static class ADUtils {
        static void sort(int[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                int a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }

        static void reverse(int[] arr) {
            int last = arr.length / 2;
            for (int i = 0; i < last; i++) {
                int tmp = arr[i];
                arr[i] = arr[arr.length - 1 - i];
                arr[arr.length - 1 - i] = tmp;
            }
        }

        static void sort(long[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                long a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }
    }

    static class MathUtils {
        static long[] FIRST_PRIMES = {
                2,     3,      5,      7,     11,     13,     17,     19,     23,     29,
                31,     37,     41,     43,     47,     53,     59,     61,     67,     71,
                73,     79,     83,     89  ,   97 ,    101,    103,    107,    109,    113,
                127,    131,    137,    139,    149,    151,    157,    163,    167,    173,
                179,    181,    191,    193,    197,    199,    211,    223,    227,    229,
                233,    239,    241,    251,    257,    263,    269,    271,    277,    281,
                283,    293,    307,    311,    313,    317,    331,    337,    347,    349,
                353,    359,    367,    373,    379,    383,    389,    397,    401,    409,
                419,    421,    431,    433,    439,    443,    449,    457,    461,    463,
                467,    479,    487,    491,    499,    503,    509,    521,    523,    541,
                547,    557,    563,    569,    571,    577,    587,    593,    599,    601,
                607,    613,    617,    619,    631,    641,    643,    647,    653,    659,
                661,    673,    677,    683,    691,    701,    709,    719,    727,    733,
                739,    743,    751,    757,    761,    769,    773,    787,    797,    809,
                811,    821,    823,    827,    829,    839,    853,    857,    859,    863,
                877,    881,    883,    887,    907,    911,    919,    929,    937,    941,
                947,    953,    967,    971,    977,    983,    991,    997,   1009,   1013,
                1019,   1021,   1031,   1033,   1039,   1049,   1051};

        static long[] primes(int to) {
            long[] all = new long[to + 1];
            long[] primes = new long[to + 1];
            all[1] = 1;
            int primesLength = 0;
            for (int i = 2; i <= to; i ++) {
                if (all[i] == 0) {
                    primes[primesLength++] = i;
                    all[i] = i;
                }
                for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) {
                    all[(int) (i * primes[j])] = primes[j];
                }
            }
            return Arrays.copyOf(primes, primesLength);
        }

        static long modpow(long b, long e, long m) {
            long result = 1;

            while (e > 0) {
                if ((e & 1) == 1) {
                    /* multiply in this bit's contribution while using modulus to keep
                     * result small */
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                e >>= 1;
            }

            return result;
        }

        static long submod(long x, long y, long m) {
            return (x - y + m) % m;
        }
    }
}

/*

 */


//package com.example.programmingpractice;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class CodeforcesNT {

    public static void main (String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int m = Integer.parseInt(br.readLine());
        String s = br.readLine();
        int[] count = new int[130];
        for(int t = 0; t<m; t++) {
            String[] inputs = br.readLine().trim().split(" ");
            int a = Integer.parseInt(inputs[0]);
            int b = Integer.parseInt(inputs[1]);
            if(s.charAt(t) == '1') {
                b += a;
                for(int i = 0; i<a; i++) count[i]++;
            }
            for(int i = b; i<count.length; i+=2*a) {
                for(int j = i; j<i+a && j<count.length; j++) {
                    count[j]++;
                }
            }
        }
        int max = count[0];
        for (int i = 1; i<count.length; i++) {
            if(max<count[i]) {
                max = count[i];
            }
        }
        System.out.println(max);
    }
}


//package com.example.programmingpractice;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class CodeforcesNT {

    public static void main (String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int m = Integer.parseInt(br.readLine());
        String s = br.readLine();
        int[] count = new int[130];
        for(int t = 0; t<m; t++) {
            String[] inputs = br.readLine().trim().split(" ");
            int a = Integer.parseInt(inputs[0]);
            int b = Integer.parseInt(inputs[1]);
            if(s.charAt(t) == '1') {
                for(int i = 0; i<b; i++) count[i]++;
                b += a;
            }
            for(int i = b; i<count.length; i+=2*a) {
                for(int j = i; j<i+a && j<count.length; j++) {
                    count[j]++;
                }
            }
        }
        int max = count[0];
        for (int i = 1; i<count.length; i++) {
            if(max<count[i]) {
                max = count[i];
            }
        }
        System.out.println(max);
    }
}


import java.io.*;
import java.util.*;

public class B {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {

        int n = r.nextInt();
        String s = r.next();

        int cnt = 0;
        for(int i = 0; i < n; i++){
            if(s.charAt(i) == '1'){
                cnt++;
            }
        }

        int[] a = new int[n]; // cycle time
        int[] b = new int[n]; // start time
        for(int i = 0; i < n; i++){
            a[i] = r.nextInt();
            b[i] = s.charAt(i) == '1' ? r.nextInt() + a[i] : r.nextInt();
        }
        int max = 0;
        for(int t = 20; t < 1000; t++){
            max = Math.max(max, ff(a, b, t));
        }
        pw.println(Math.max(max, cnt));
        pw.close();
    }

    public static int ff(int[] a, int[] b, int t){
        int total = 0, n = a.length;
        for(int i = 0; i < n; i++){
            if((t - b[i]) % (2 * a[i]) < a[i]){
                total++;
            }
        }
        return total;
    }
}

/**
*                _        _                 _
*               | |      | |               | |
*   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___
*  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \
* | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
*  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/
*                                __/ |                               ______ __/ |
*                               |___/                               |______|___/
 */


import java.io.*;
import java.util.*;

public class B {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {

        int n = r.nextInt();
        String s = r.next();

        int[] a = new int[n]; // cycle time
        int[] b = new int[n]; // start time
        for(int i = 0; i < n; i++){
            a[i] = r.nextInt();
            b[i] = r.nextInt();
        }

        boolean[] lights = new boolean[n];
        for(int i = 0; i < n; i++){
            if(s.charAt(i) == '1'){
                lights[i] = true;
            }
        }
        int max = sum(lights);
        for(int t = 0; t < 1000; t++){
            for(int i = 0; i < n; i++){
                if(ff(a[i], b[i], t)){
                    lights[i] = !lights[i];
                }
            }
            max = Math.max(max, sum(lights));
        }
        pw.println(max);
        pw.close();
    }

    public static boolean ff(int a, int b, int t){
        return t >= b && (t - b) % a == 0;
    }

    public static int sum(boolean[] arr){
        int ret = 0;
        for(int i = 0; i < arr.length; i++){
            if(arr[i]) ret++;
        }
        return ret;
    }
}

/**
*                _        _                 _
*               | |      | |               | |
*   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___
*  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \
* | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
*  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/
*                                __/ |                               ______ __/ |
*                               |___/                               |______|___/
 */


import java.io.*;
import java.util.*;

public class B {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {

        int n = r.nextInt();
        String s = r.next();

        int cnt = 0;
        for(int i = 0; i < n; i++){
            if(s.charAt(i) == '1'){
                cnt++;
            }
        }

        int[] a = new int[n]; // cycle time
        int[] b = new int[n]; // start time
        for(int i = 0; i < n; i++){
            a[i] = r.nextInt();
            b[i] = s.charAt(i) == '1' ? r.nextInt() + a[i] : r.nextInt();
        }
        int max = 0;
        for(int t = 0; t < 1000; t++){
            max = Math.max(max, ff(a, b, t));
        }
        pw.println(Math.max(max, cnt));
        pw.close();
    }

    public static int ff(int[] a, int[] b, int t){
        int total = 0, n = a.length;
        for(int i = 0; i < n; i++){
            if((t - b[i]) % (2 * a[i]) < a[i]){
                total++;
            }
        }
        return total;
    }
}

/**
*                _        _                 _
*               | |      | |               | |
*   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___
*  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \
* | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
*  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/
*                                __/ |                               ______ __/ |
*                               |___/                               |______|___/
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForcesTwo {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int n = fastReader.nextInt();

        char [] charArray= fastReader.next().toCharArray();

        List<Time> list = new ArrayList<Time>();
        int max=0;
        for(int i=0;i<n;i++){
            int start= fastReader.nextInt();
            int stop = fastReader.nextInt();

            max=Math.max(max,start+stop);
            list.add(new Time(start,stop));
        }

        int counter=0;
        for(int j=0;j<n;j++){
            if(charArray[j]=='1'){
                counter+=1;
            }
        }

        if(counter==charArray.length){
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(counter);
            writer.flush();
        }
        else {
            int answer = Integer.MIN_VALUE;
            for (int i = 0; i <= 10000000; i++) {
                int count = 0;

                for (int j = 0; j < n; j++) {
                    Time t = list.get(j);

                    if ((i - t.stop > 0) && (i - t.stop) % t.start == 0) {
                        charArray[j] = charArray[j] == '1' ? '0' : '1';
                    }
                }

                for (int j = 0; j < n; j++) {
                    if (charArray[j] == '1') {
                        count += 1;
                    }
                }
                answer = Math.max(count, answer);
            }
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(answer);
            writer.flush();
        }
    }

    static class Time{
        int start;
        int stop;
        Time(int start,int stop){
            this.start = start;
            this.stop = stop;
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForcesTwo {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int n = fastReader.nextInt();

        char [] charArray= fastReader.next().toCharArray();

        List<Time> list = new ArrayList<Time>();
        int max=0;
        for(int i=0;i<n;i++){
            int start= fastReader.nextInt();
            int stop = fastReader.nextInt();

            max=Math.max(max,start+stop);
            list.add(new Time(start,stop));
        }

        int counter=0;
        for(int j=0;j<n;j++){
            if(charArray[j]=='1'){
                counter+=1;
            }
        }

        if(counter==charArray.length){
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(counter);
            writer.flush();
        }
        else {
            int answer = Integer.MIN_VALUE;
            for (int i = 0; i <= 100000000; i++) {
                int count = 0;

                for (int j = 0; j < n; j++) {
                    Time t = list.get(j);

                    if ((i - t.stop > 0) && (i - t.stop) % t.start == 0) {
                        charArray[j] = charArray[j] == '1' ? '0' : '1';
                    }
                }

                for (int j = 0; j < n; j++) {
                    if (charArray[j] == '1') {
                        count += 1;
                    }
                }
                answer = Math.max(count, answer);
            }
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(answer);
            writer.flush();
        }
    }

    static class Time{
        int start;
        int stop;
        Time(int start,int stop){
            this.start = start;
            this.stop = stop;
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForcesTwo {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int n = fastReader.nextInt();

        char [] charArray= fastReader.next().toCharArray();

        List<Time> list = new ArrayList<Time>();
        int max=0;
        for(int i=0;i<n;i++){
            int start= fastReader.nextInt();
            int stop = fastReader.nextInt();

            max=Math.max(max,start+stop);
            list.add(new Time(start,stop));
        }

        int answer=Integer.MIN_VALUE;
        for(int i=0;i<=10000;i++){
            int count=0;
            for(int j=0;j<n;j++){
                Time t = list.get(j);

                if((i-t.stop>0) && (i-t.stop)%t.start==0){
                    charArray[j]=charArray[j]=='1'?'0':'1';
                }
            }

            for(int j=0;j<n;j++){
                if(charArray[j]=='1'){
                    count+=1;
                }
            }
            answer = Math.max(count, answer);

            PrintWriter writer = new PrintWriter(System.out);

            writer.println(answer);
            writer.flush();
        }
    }

    static class Time{
        int start;
        int stop;
        Time(int start,int stop){
            this.start = start;
            this.stop = stop;
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}