Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so unlucky that he hasn’t entered the code where would be more than 5 correct numbers. Now Vasya is completely bewildered: he thinks there’s a mistake in the system and it is self-contradictory. Help Vasya — calculate how many possible code variants are left that do not contradict the previous system responses.

Input

The first input line contains two integers n and m (6 ≤ n ≤ 35, 1 ≤ m ≤ 10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow m lines, each containing space-separated si and ci which correspondingly indicate Vasya’s attempt (a line containing n numbers which are 0 or 1) and the system’s response (an integer from 0 to 5 inclusively).

Output

Print the single number which indicates how many possible code variants that do not contradict the m system responses are left.

Examples

Input

6 2
000000 2
010100 4


Output

6


Input

6 3
000000 2
010100 4
111100 0


Output

0


Input

6 3
000000 2
010100 4
111100 2


Output

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

public class Main {
    static int n;
    static ArrayList<String> passPermutations;
    public static void permute(String s, int idx, int toBeChangedCount){
        if(toBeChangedCount == 0) {
            passPermutations.add(s);
            return;
        }
        if(idx == n || n-idx < toBeChangedCount) return;

        //change 1 -> 0 & 0 -> 1
        permute(s.substring(0, idx) + (s.charAt(idx) == '0' ? "1" : "0") + s.substring(idx+1), idx+1, toBeChangedCount-1);
        //leave as is
        permute(s, idx+1, toBeChangedCount);
    }

    public static int countSame(String s1, String s2){
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if(s1.charAt(i) == s2.charAt(i)) cnt++;
        }
        return cnt;
    }

    public static void main(String[] args) throws IOException {
        n = sc.nextInt(); int m = sc.nextInt();
        passPermutations = new ArrayList<>();
        String initialPass = sc.next(); int initialC = sc.nextInt();
        permute(initialPass, 0, n-initialC);
//        pw.println(passPermutations.size());

        Pair[] passes = new Pair[m];
        for (int i = 1; i < m; i++) {
            passes[i] = new Pair(sc.next(), sc.nextInt());
        }

        int ans = 0;
        for(String currPassPerm : passPermutations){
            boolean f = true;
            for(int i = 1; i < m; i++) {
                Pair pass_c = passes[i];
                String pass = pass_c.first;
                int same = countSame(currPassPerm, pass);
                if(same != pass_c.second) {
                    f = false;
                    break;
                }
            }

            if(f) {
//                pw.println(currPassPerm);
                ans++;
            }
        }
        pw.println(ans);

        pw.close();
    }

    //    public static void pairSort(Pair[] arr) {
//        ArrayList<Pair> l = new ArrayList<>();
//        Collections.addAll(l, arr);
//        Collections.sort(l);
//        for (int i = 0; i < arr.length; i++) {
//            arr[i] = l.get(i);
//        }
//    }
    public static void longSort(long[] arr) {
        ArrayList<Long> l = new ArrayList<>();
        for (long i : arr) l.add(i);
        Collections.sort(l);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = l.get(i);
        }
    }
    public static void intSort(int[] arr) {
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : arr) l.add(i);
        Collections.sort(l);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = l.get(i);
        }
    }

    static class Pair {
        String first; int second;
        public Pair(String first, int second){
            this.first = first; this.second = second;
        }

//        @Override
//        public int compareTo(Pair p2) {
//            if(x == p2.x) return y - p2.y;
//            else return x - p2.x;
//        }

        //        @Override
        public String toString() { return "("+ first + "," + second + ')'; }

    }
    static class Triple {
        int x, y, z;

        Triple(int a, int b, int c) { x = a; y = b; z = c;}


        //        public int compareTo(Triple t)
//        {
//            if(Math.abs(sum - t.sum) < 1e-9) return x > t.x ? 1 : -1;
//            return sum > t.sum ? 1 : -1;
//        }
        public String toString()
        {
            return "(" + x + ", " + y  + ", " + z + ")";
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = Integer.parseInt(next());
            }
            return arr;
        }

        public long[] nextLongArr(int n) throws IOException {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = Long.parseLong(next());
            }
            return arr;
        }

    }
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static Random random = new Random();
    static final long MOD = 1_000_000_000 + 7;
}