#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i;
  cin >> n >> m;
  string s_i_bin;
  unsigned long long int s_i[m];
  int c_i[m];
  for (i = 0; i < m; ++i) {
    cin >> s_i_bin >> c_i[i];
    s_i[i] = stoull(s_i_bin, 0, 2);
  }
  int min_ind = 0, min_c = 40;
  for (i = 0; i < m; ++i) {
    if (c_i[i] < min_c) {
      min_c = c_i[i];
      min_ind = i;
    }
  }
  unsigned long long int xor_with = s_i[min_ind];
  set<unsigned long long int> xored, next;
  unsigned long long int t, v, w;
  v = (1 << min_c) - 1;
  do {
    xored.insert(v ^ xor_with);
    t = v | (v - 1);
    w = (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(v) + 1));
    v = w;
  } while (w >> n == 0);
  int diff, count_bits;
  unsigned long long int aux;
  for (i = 0; i < m; ++i) {
    if (i == min_ind) continue;
    xor_with = s_i[i];
    diff = c_i[i];
    for (unsigned long long int x : xored) {
      aux = x ^ xor_with;
      count_bits = 0;
      while (aux && count_bits <= diff) {
        count_bits++;
        aux &= (aux - 1);
      }
      if (count_bits == diff) next.insert(x);
    }
    xored = next;
    next.clear();
  }
  cout << xored.size() << endl;
  return 0;
}
