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