#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x, y;
  y = scanf("%d", &x);
  return x;
}
const int N = 40;
string s[N];
int cor[N], n, m, ans;
bool mark[N];
bool check(string t) {
  for (int i = 0; i < (m); i++) {
    int cnt = 0;
    for (int j = 0; j < (n); j++) cnt += (t[j] != s[i][j]);
    if (cnt != cor[i]) return false;
  }
  return true;
}
void bt(int d, string t, int lst) {
  if (d == 0) {
    ans += check(t);
    return;
  }
  if (lst == n) return;
  for (int i = lst; i < n; i++)
    if (!mark[i]) {
      t[i] = '1' - t[i] + '0';
      mark[i] = !mark[i];
      bt(d - 1, t, i + 1);
      t[i] = '1' - t[i] + '0';
      mark[i] = !mark[i];
    }
}
int main() {
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  uniform_int_distribution<long long> distr;
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (m); i++) cin >> s[i] >> cor[i];
  bt(cor[0], s[0], 0);
  cout << ans << endl;
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
