#include <bits/stdc++.h>
using namespace std;
struct hammer {
  string code;
  int cor;
} box[14];
int n, m;
int correct[8];
string s;
int ri;
int cmp(const hammer& a, const hammer& b) {
  if (a.cor < b.cor)
    return 1;
  else
    return 0;
}
int sum = 0;
void dfs(int now, int step) {
  if (step == ri + 1) {
    int no = 1;
    string s2 = "";
    for (int i = 0; i < n; i++) {
      if (no <= ri && i == correct[no]) {
        no++;
        s2 += s[i];
      } else {
        if (s[i] == '1')
          s2 += '0';
        else
          s2 += '1';
      }
    }
    bool con = 0;
    for (int i = 2; i <= m; i++) {
      int su = 0;
      for (int j = 0; j < n; j++) {
        if (box[i].code[j] == s2[j]) su++;
      }
      if (su != box[i].cor) {
        con = 1;
        break;
      }
    }
    if (!con) sum++;
    return;
  }
  for (int i = now; i < n; i++) {
    correct[step] = i;
    dfs(i + 1, step + 1);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> box[i].code >> box[i].cor;
  sort(box + 1, box + 1 + m, cmp);
  s = box[1].code;
  ri = box[1].cor;
  dfs(0, 1);
  cout << sum << endl;
  return 0;
}
