#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, k;
  string in;
  list<string> ret;
  cin >> N >> M;
  cin >> in >> k;
  if (k == 0) {
    for (int i = 0; i < N; i++) in[i] = ((in[i] - '0') ^ 1) + '0';
    ret.push_back(in);
  } else {
    long long s = (1LL << k) - 1;
    while (!(s & 1LL << N)) {
      string c = in;
      for (int i = 0; i < N; i++)
        if (!(s & (1LL << i))) c[i] = ((c[i] - '0') ^ 1) + '0';
      ret.push_back(c);
      long long lo = s & ~(s - 1);
      long long lz = (s + lo) & ~s;
      s |= lz;
      s &= ~(lz - 1);
      s |= (lz / lo / 2) - 1;
    }
  }
  for (int i = 1; i < M; i++) {
    cin >> in >> k;
    list<string>::iterator it = ret.begin();
    while (it != ret.end()) {
      int c = 0;
      for (int j = 0; j < N; j++)
        if ((*it)[j] == in[j]) c++;
      if (c != k)
        it = ret.erase(it);
      else
        it++;
    }
  }
  cout << ret.size();
  return 0;
}
