#include <bits/stdc++.h>
using namespace std;
int N, M;
long long fromString(string str) {
  long long t = 1, n = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[str.size() - i - 1] - '0') {
      n += t;
    }
    t *= 2;
  }
  return n;
}
long long fromIntArray(int *pp) {
  long long t = 1, n = 0;
  for (int i = 0; i < N; i++) {
    if (pp[i]) {
      n += t;
    }
    t *= 2;
  }
  return n;
}
long long bitsCount(long long n) {
  int c = 0;
  while (n) {
    n &= (n - 1);
    c++;
  }
  return c;
}
int main() {
  cin >> N >> M;
  cin.ignore();
  int pp[40];
  fill(pp, &pp[N], 1);
  string str;
  int p;
  cin >> str >> p;
  cin.ignore();
  for (int i = 0; i < p; i++) {
    pp[i] = 0;
  }
  vector<long long> v;
  do {
    v.push_back(fromString(str) ^ fromIntArray(pp));
  } while (next_permutation(pp, &pp[N]));
  for (int i = 1; i < M; i++) {
    cin >> str >> p;
    cin.ignore();
    vector<long long> vv(0);
    for (int j = 0; j < v.size(); j++) {
      if (bitsCount((((long long)1 << N) - 1) & (~(fromString(str) ^ v[j]))) ==
          p) {
        vv.push_back(v[j]);
      }
    }
    v.clear();
    for (int i = 0; i < vv.size(); i++) {
      v.push_back(vv[i]);
    }
  }
  cout << v.size() << endl;
  return 0;
}
