#include <bits/stdc++.h>
using namespace std;
char s[50][50];
int n, m;
int num[50];
int dfs(int deep) {
  if (deep == n) {
    for (int i = 1; i <= m; i++)
      if (num[i]) return 0;
    return 1;
  }
  int ans = 0;
  for (char now = '0'; now <= '1'; now++) {
    bool biaoji = true;
    for (int i = 1; i <= m; i++)
      if (now == s[i][deep]) {
        num[i]--;
        if (num[i] < 0) biaoji = false;
      }
    if (biaoji) ans += dfs(deep + 1);
    for (int i = 1; i <= m; i++)
      if (now == s[i][deep]) num[i]++;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%s %d", s[i], &num[i]);
  int ans = dfs(0);
  printf("%d", ans);
  return 0;
}
