#include <bits/stdc++.h>
using namespace std;
void inputSet(set<long long> &S) {
  string str, ss;
  int c, i, n;
  long long so;
  cin >> str >> c;
  n = str.size();
  for (i = 0; i < c; i++) ss += '0';
  for (i = 0; i < n - c; i++) ss += '1';
  S.clear();
  do {
    so = 0;
    for (i = 0; i < n; i++) so = (so << 1) | (str[i] ^ ss[i]);
    S.insert(so);
  } while (next_permutation(ss.begin(), ss.end()));
}
int main() {
  int n, m;
  set<long long> S1, S2, S3;
  cin >> n >> m;
  inputSet(S1);
  while (--m) {
    inputSet(S2);
    set_intersection(S1.begin(), S1.end(), S2.begin(), S2.end(),
                     inserter(S3, S3.begin()));
    S1 = S3;
    S3.clear();
  }
  cout << S1.size() << endl;
  return 0;
}
