#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[13];
int b[13];
int ans = 0;
char s[43];
int coun(long long a) {
  int ans = 0;
  while (a > 0) {
    if (a & 1) ans++;
    a >>= 1;
  }
  return ans;
}
char check(long long value) {
  for (int i = 0; i < n; i++) value ^= ((long long)1) << i;
  long long res = a[0] ^ value;
  for (int i = 1; i < m; i++)
    if (coun(a[i] ^ res) != n - b[i]) return 0;
  return 1;
}
void dfs(int u, int v, long long value) {
  if (v == b[0]) {
    if (check(value)) ans++;
    return;
  }
  for (int i = u; i < n; i++) {
    dfs(i + 1, v + 1, value | ((long long)1 << i));
  }
}
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < m; i++) {
      scanf("%s%d", s, b + i);
      a[i] = 0;
      for (int j = 0; s[j]; j++) a[i] = (a[i] << 1) + s[j] - '0';
    }
    ans = 0;
    dfs(0, 0, 0);
    printf("%d\n", ans);
  }
  return 0;
}
