#include <bits/stdc++.h>
using namespace std;
string str[50];
int b[20];
int c[3500000][10];
int fun(string s, string t) {
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != t[i]) ans = ans + 1;
  }
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x;
    string st;
    cin >> st >> x;
    str[i] = st;
    b[i] = x;
  }
  int ans = 0;
  int pos = 0;
  for (int i = 0; i < n; i++) {
    c[pos][0] = i;
    if (b[0] > 1) {
      for (int j = i + 1; j < n; j++) {
        c[pos][0] = i;
        c[pos][1] = j;
        if (b[0] > 2) {
          for (int ii = j + 1; ii < n; ii++) {
            c[pos][0] = i;
            c[pos][1] = j;
            c[pos][2] = ii;
            if (b[0] > 3) {
              for (int iii = ii + 1; iii < n; iii++) {
                c[pos][0] = i;
                c[pos][1] = j;
                c[pos][2] = ii;
                c[pos][3] = iii;
                if (b[0] > 4) {
                  for (int iiii = iii + 1; iiii < n; iiii++) {
                    c[pos][0] = i;
                    c[pos][1] = j;
                    c[pos][2] = ii;
                    c[pos][3] = iii;
                    c[pos][4] = iiii;
                    if (b[0] == 5) pos++;
                  }
                }
                if (b[0] == 4) pos++;
              }
            }
            if (b[0] == 3) pos++;
          }
        }
        if (b[0] == 2) pos++;
      }
    }
    if (b[0] == 1) pos++;
  }
  int k = 0;
  for (int i = 0; i < pos; i++) {
    string u = str[0];
    for (int j = 0; j < b[0]; j++) {
      if (u[c[i][j]] == '0')
        u[c[i][j]] = '1';
      else
        u[c[i][j]] = '0';
    }
    k = 0;
    while (k < m) {
      if (fun(u, str[k]) == b[k])
        k = k + 1;
      else
        break;
    }
    if (k == m) ans += 1;
  }
  printf("%d\n", ans);
  return 0;
}
