#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 1000000007;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, sz1, sz2;
string s[20];
map<vector<int>, int> cnt;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vi a;
  sz1 = n / 2, sz2 = n - sz1;
  a.resize(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> a[i];
  for (ll msk = 0; msk < 1 << sz1; msk++) {
    vi t(m);
    for (int j = 0; j < m; j++)
      for (int i = 0; i < sz1; i++) {
        t[j] += (s[j][i] - '0') == ((msk >> i) & 1);
      }
    cnt[t]++;
  }
  ll ans = 0;
  for (ll msk = 0; msk < 1 << sz2; msk++) {
    vi t = a;
    for (int j = 0; j < m; j++)
      for (int i = 0; i < sz2; i++) {
        t[j] -= (s[j][sz1 + i] - '0') == ((msk >> i) & 1);
      }
    ans += cnt[t];
  }
  cout << ans;
}
