#include <bits/stdc++.h>
char s[10][36], now[36];
int n, m, ans, c[10];
void dfs(int p, int r) {
  if (p == n) {
    bool f = 1;
    int i, j, cnt;
    for (i = 1; i < m; i++) {
      cnt = 0;
      for (j = 0; j < n; j++)
        if (s[i][j] == now[j]) cnt++;
      if (cnt != c[i]) {
        f = 0;
        break;
      }
    }
    if (f) ans++;
  } else {
    if (n - 1 - p >= r) {
      now[p] = (s[0][p] == '0' ? '1' : '0');
      dfs(p + 1, r);
    }
    if (r) {
      now[p] = s[0][p];
      dfs(p + 1, r - 1);
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < m; i++) scanf("%s%d", s[i], c + i);
    ans = 0;
    dfs(0, c[0]);
    printf("%d\n", ans);
  }
  return 0;
}
