#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6;
const long long MAXL = 35;
bitset<MAXL> cur, bt[MAXN], res[MAXN];
long long sz = 0;
void genarate(long long a, long long b) {
  if (b == 0) {
    res[sz++] = cur;
    return;
  }
  cur[b - 1] = true;
  if (a > 0) genarate(a - 1, b - 1);
  cur[b - 1] = false;
  if (a < b) genarate(a, b - 1);
  return;
}
long long a[MAXN];
int32_t main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      char ch;
      cin >> ch;
      bt[i][j] = ch - '0';
    }
    cin >> a[i];
  }
  genarate(a[0], n);
  long long ans = 0;
  for (long long k = 0; k < sz; k++) {
    cur = bt[0] ^ res[k];
    long long i = 0;
    while (i < m && (cur ^ bt[i]).count() == a[i]) i++;
    ans += (i == m);
  }
  cout << ans;
}
