#include <bits/stdc++.h>
using namespace std;
void solutionD();
int main() {
  ios_base::sync_with_stdio(false);
  solutionD();
  return EXIT_SUCCESS;
}
long long n, m;
string s[16];
long long c[16], e[64];
set<long long> t;
void dfs(long long v, long long last, long long i) {
  if (v == c[i]) {
    long long r = 0, p = 1;
    for (long long j = 0; j < n; ++j) {
      if (e[j]) {
        if (s[i][j] == '1') r |= p;
      } else {
        if (s[i][j] == '0') r |= p;
      }
      p <<= 1;
    }
    t.insert(r);
    return;
  }
  for (long long j = last + 1; j < n; ++j) {
    e[j] = 1;
    dfs(v + 1, j, i);
    e[j] = 0;
  }
}
void solve() {
  for (long long i = 0; i < m; ++i)
    for (long long j = i + 1; j < m; ++j) {
      long long d = 0;
      for (long long k = 0; k < n; ++k)
        if (s[i][k] != s[j][k]) ++d;
      if (abs(c[i] - c[j]) > d) {
        cout << 0 << endl;
        return;
      }
    }
  set<long long> ans;
  for (long long i = 0; i < m; ++i) {
    t.clear();
    memset(e, 0, sizeof(long long) * 64);
    dfs(0, -1, i);
    set<long long> ans_n;
    if (i == 0) {
      ans_n = t;
    } else {
      for (long long j : t)
        if (ans.count(j)) ans_n.insert(j);
    }
    ans = ans_n;
  }
  cout << ans.size() << endl;
}
void solutionD() {
  for (; cin >> n >> m;) {
    for (long long i = 0; i < m; ++i) cin >> s[i] >> c[i];
    solve();
    cerr << endl;
  }
}
