#include <bits/stdc++.h>
using namespace std;
int n, m, s[12], a_s, mark[500000];
char str[12][38];
char sum[500000][38], tmp[38];
char tr(char x) {
  if (x == '0') return '1';
  return '0';
}
int sea(int x, int y) {
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    if (sum[y][i] == str[x][i]) ret++;
  }
  return ret;
}
void dfs(int x, int y) {
  if (x > n) {
    if (y <= 0) {
      tmp[x] = '\0';
      strcpy(sum[++a_s] + 1, tmp + 1);
    }
    return;
  }
  if (y <= 0) {
    tmp[x] = tr(str[1][x]);
    dfs(x + 1, y);
  } else {
    tmp[x] = tr(str[1][x]);
    dfs(x + 1, y);
    tmp[x] = str[1][x];
    dfs(x + 1, y - 1);
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= m; i++) {
      scanf("%s%d", str[i] + 1, &s[i]);
    }
    memset(mark, 0, sizeof(mark));
    a_s = 0;
    dfs(1, s[1]);
    int sum = a_s;
    for (int i = 2; i <= m; i++) {
      for (int j = 1; j <= a_s; j++) {
        if (mark[j]) continue;
        int tm = sea(i, j);
        if (tm != s[i]) {
          sum--;
          mark[j] = 1;
        }
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}
