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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;

/**
 * @author Egor Kulikov (egor@egork.net)
 */
public class TaskD {
    @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
    InputReader in;
    PrintWriter out;
    boolean[] ones;
    private boolean[][] s;
    private int[] c;

    void solve() {
        int n = in.readInt();
        int m = in.readInt();
        s = new boolean[m][n];
        c = new int[m];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++)
                s[i][j] = in.readCharacter() == '1';
            c[i] = in.readInt();
        }
        ones = new boolean[n];
        out.println(go(0, c[0], s[0]));
    }

    private int go(int step, int errors, boolean[] example) {
        if (step == example.length) {
            if (errors != 0)
                return 0;
            for (int i = 1; i < s.length; i++) {
                int rowErrors = 0;
                for (int j = 0; j < example.length; j++) {
                    if (ones[j] != s[i][j])
                        rowErrors++;
                }
                if (rowErrors != c[i])
                    return 0;
            }
            return 1;
        }
        ones[step] = example[step];
        int res = go(step + 1, errors, example);
        ones[step] = !example[step];
        if (errors != 0)
            res += go(step + 1, errors - 1, example);
        return res;
    }

    public static void main(String[] args) {
        new TaskD().run();
    }

    TaskD() {
        @SuppressWarnings({"UnusedDeclaration"})
        String id = getClass().getName().toLowerCase();
        //noinspection EmptyTryBlock
        try {
//          System.setIn(new FileInputStream(id + ".in"));
//          System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//          System.setIn(new FileInputStream("input.txt"));
//          System.setOut(new PrintStream(new FileOutputStream("output.txt")));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
    }

    void run() {
        //noinspection InfiniteLoopStatement
        solve();
        exit();
    }

    @SuppressWarnings({"UnusedDeclaration"})
    void exit() {
        out.close();
        System.exit(0);
    }

    @SuppressWarnings({"UnusedDeclaration"})
    static class InputReader {
        InputStream stream;
        byte[] buf = new byte[1024];
        int curChar, numChars;

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

        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++];
        }

        int readInt() {
            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;
        }

        long readLong() {
            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;
        }

        String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            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;
        }

        String readLine0() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

        String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines)
                return readLine();
            else
                return readLine0();
        }

        BigInteger readBigInteger() {
            try {
                return new BigInteger(readString());
            } catch (NumberFormatException e) {
                throw new InputMismatchException();
            }
        }

        char readCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        double readDouble() {
            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, readInt());
                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, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
    }
}