#include <bits/stdc++.h>
using namespace std;
const long long MAX = 36, MAXN = 20;
long long a[MAXN], cnt[MAXN];
set<long long> s[MAXN];
long long k;
long long n, m;
void find(long long now, long long cnt, set<long long>& st, long long& r) {
  if (now == n) {
    if (!cnt) st.insert(k ^ r);
    return;
  }
  k <<= 1;
  find(now + 1, cnt, st, r);
  if (cnt) {
    ++k;
    find(now + 1, cnt - 1, st, r);
  }
  k >>= 1;
}
int32_t main() {
  char a1;
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    for (long long j = 0; j < n; ++j) {
      cin >> a1;
      a[i] = (a[i] << 1) + a1 - '0';
    }
    cin >> cnt[i];
    find(0, cnt[i], s[i], a[i]);
  }
  long long ans = 0;
  for (auto i : s[0]) {
    bool k = true;
    for (long long j = 1; j < m; ++j)
      if (!s[j].count(i)) k = false;
    ans += k;
  }
  cout << ans;
  return 0;
}
