#include <bits/stdc++.h>
using namespace std;
char s[40][40];
char r[40], h[40];
int cnt[40];
int n, m, ans;
void reset() {
  memset(s, 0, sizeof s);
  memset(h, 0, sizeof h);
  memset(r, 0, sizeof r);
  memset(cnt, 0, sizeof cnt);
}
void permutation(int j) {
  int i, c, ans, sum = 0, k;
  sort(r, r + n);
  do {
    for (i = 0; i < n; i++) {
      if (r[i] == '1') {
        h[i] = s[j][i];
      } else {
        if (s[j][i] == '1') {
          h[i] = '0';
        } else
          h[i] = '1';
      }
    }
    ans = 1;
    for (i = 0; i < m; i++) {
      c = 0;
      if (i == j) continue;
      for (k = 0; k < n; k++) {
        if (s[i][k] == h[k]) c++;
      }
      if (c != cnt[i]) {
        ans = 0;
        break;
      }
    }
    sum += ans;
  } while (next_permutation(r, r + n));
  printf("%d\n", sum);
}
int main() {
  int i, j = 0;
  scanf("%d%d", &n, &m);
  reset();
  for (i = 0; i < m; i++) {
    cin >> s[i] >> cnt[i];
    if (j < cnt[i]) j = i;
  }
  for (i = 0; i < cnt[j]; i++) {
    r[i] = '1';
  }
  while (i < n) {
    r[i] = '0';
    i++;
  }
  permutation(j);
  return 0;
}
