#include <bits/stdc++.h>
using namespace std;
map<long long, int> cont;
map<long long, bool> used;
int n, m, res;
char num[36];
long long h;
void go(int x, int e) {
  if (!e) {
    h = 0LL;
    for (int i = 0; i < n; i++) {
      h *= 2LL;
      h += num[i] - '0';
    }
    int k = ++cont[h];
    if (k == m && !used[h]) res++;
    return;
  }
  num[x] = '1' - num[x] + '0';
  go(x + 1, e - 1);
  num[x] = '1' - num[x] + '0';
  if (n - x != e) go(x + 1, e);
  return;
}
int main() {
  int k;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf(" %s %d", num, &k);
    h = 0LL;
    for (int j = 0; j < n; j++) {
      h *= 2LL;
      h += num[j] - '0';
    }
    used[h] = true;
    go(0, n - k);
  }
  printf("%d\n", res);
  return 0;
}
