#include <bits/stdc++.h>
const int maxn = 40;
const int maxk = 10;
char s[maxk][maxn];
int a[maxk], t[maxk], n, m, ans;
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) scanf("%s%d", s[i], &a[i]);
}
void dfs(int dep) {
  for (int i = 0; i < m; ++i) {
    if (a[i] < t[i]) return;
  }
  for (int i = 0; i < m; ++i) {
    if (t[i] + n - dep < a[i]) return;
  }
  if (dep == n) {
    ++ans;
    return;
  }
  for (int i = 0; i < m; ++i) {
    t[i] += s[i][dep] == '0';
  }
  dfs(dep + 1);
  for (int i = 0; i < m; ++i) {
    t[i] -= s[i][dep] == '0';
    t[i] += s[i][dep] == '1';
  }
  dfs(dep + 1);
  for (int i = 0; i < m; ++i) {
    t[i] -= s[i][dep] == '1';
  }
}
void work() {
  dfs(0);
  printf("%d\n", ans);
}
int main() {
  init();
  work();
  return 0;
}
