#include <bits/stdc++.h>
using namespace std;
char str[100][100];
int corr[100], n, m;
vector<long long> ve;
void dfs(int x, int deep, long long res) {
  if (deep == corr[m]) {
    ve.push_back(res);
    return;
  }
  int i;
  for (i = x; i < n; i++) dfs(i + 1, deep + 1, (res | (1LL << i)));
}
int main() {
  int i, j, k;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%s %d", str[i], &corr[i]);
  dfs(0, 0, 0LL);
  int sum = 0;
  for (i = 0; i < ve.size(); i++) {
    long long tem = ve[i];
    for (j = 0; j <= 36; j++) {
      if (!(tem & (1LL << j))) {
        if (str[m][j] == '0')
          str[m][j] = '1';
        else
          str[m][j] = '0';
      }
    }
    for (j = 1; j < m; j++) {
      int flag = 0;
      for (k = 0; k < n; k++)
        if (str[j][k] == str[m][k]) flag++;
      if (flag != corr[j]) break;
    }
    if (j >= m) sum++;
    for (j = 0; j <= 36; j++) {
      if (!(tem & (1LL << j))) {
        if (str[m][j] == '0')
          str[m][j] = '1';
        else
          str[m][j] = '0';
      }
    }
  }
  printf("%d\n", sum);
  return 0;
}
