#include <bits/stdc++.h>
using namespace std;
int n, m, correct[15], C[40];
string in[15];
char rev(char c) { return (c == '0' ? '1' : '0'); }
int ok(string s) {
  int i, j;
  for (i = 0; i < m; i++) {
    int cnt = 0;
    for (j = 0; j < n; j++) cnt += (in[i][j] == s[j]);
    if (cnt != correct[i]) return 0;
  }
  return 1;
}
int main() {
  int i;
  cin >> n >> m;
  for (i = 0; i < m; i++) cin >> in[i] >> correct[i];
  for (i = 0; i < n; i++) C[i] = 0;
  for (i = 0; i < correct[0]; i++) C[n - i - 1] = 1;
  int ret = 0;
  do {
    string s = "";
    for (i = 0; i < n; i++)
      if (C[i])
        s += in[0][i];
      else
        s += rev(in[0][i]);
    ret += ok(s);
  } while (next_permutation(C, C + n));
  cout << ret;
  return 0;
}
