#include <bits/stdc++.h>
int l, m, sum[15];
char st[15][50];
int find(int n, int side[50], char stb[50], int k) {
  int i, j, count, ss, s = 0, l1;
  char sta[50];
  if (n > 0) {
    ss = 0;
    for (i = 0; i < l; i++) {
      if (side[i]) s++;
      if (s == (k - n)) break;
    }
    l1 = i;
    if (n == k)
      i = 0;
    else
      i = l1 + 1;
    for (; i < l; i++) {
      if (!side[i]) {
        side[i] = 1;
        ss += find(n - 1, side, stb, k);
        side[i] = 0;
      }
    }
    return ss;
  } else {
    strcpy(sta, stb);
    for (i = 0; i < l; i++) {
      if (side[i] == 0) sta[i] = 1 ^ (sta[i] - '0') + '0';
    }
    for (i = 0; i < m; i++) {
      count = 0;
      for (j = 0; j < l; j++) {
        if (sta[j] == st[i][j]) count++;
      }
      if (count != sum[i]) return 0;
    }
    return 1;
  }
}
int main() {
  int i, j, k, n, side[50], s;
  char sta[50];
  while (scanf("%d%d", &l, &m) != EOF) {
    n = 0;
    for (i = 0; i < m; i++) {
      scanf(" %s %d", st[i], &sum[i]);
      n = sum[n] < sum[i] ? n : i;
    }
    memset(side, 0, sizeof(side));
    strcpy(sta, st[n]);
    s = find(sum[n], side, sta, sum[n]);
    printf("%d\n", s);
  }
  return 0;
}
