#include <bits/stdc++.h>
using namespace std;
char ar[16][64];
int n, m;
map<vector<char>, int> mp;
long long res;
vector<char> t, S;
void sub(vector<char> &v) {
  for (int i = 0; i < m; i++) {
    t[i] = S[i] - v[i];
  }
}
int main() {
  scanf("%d%d\n", &n, &m);
  t.resize(m);
  S.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%s", ar[i]);
    int z;
    scanf("%d", &z);
    S[i] = z;
  }
  int k = n / 2;
  vector<char> v;
  for (int i = 0; i < (1 << k); i++) {
    v.assign(m, 0);
    for (int j = 0; j < m; j++) {
      for (int z = 0; z < k; z++) {
        if (ar[0][z] == ar[j][z] ^ !(i & (1 << z))) v[j]++;
      }
    }
    mp[v]++;
  }
  k = n - k;
  for (int i = 0; i < (1 << k); i++) {
    v.assign(m, 0);
    for (int j = 0; j < m; j++) {
      for (int z = 0; z < k; z++) {
        if (ar[0][z + n / 2] == ar[j][z + n / 2] ^ !(i & (1 << z))) v[j]++;
      }
    }
    sub(v);
    res += mp[t];
  }
  printf("%lld\n", res);
  return 0;
}
