#include <bits/stdc++.h>
const int INF = 1e7;
using namespace std;
const int N = 20;
int n, m;
int c[N];
int a[N];
int like[N];
string s[N];
int T_res = 0;
int Lika = 0;
bool Check_Res() {
  int Lik;
  for (int i = 2; i <= m; i++) {
    {
      Lik = 0;
      for (int j = 0; j <= n - 1; j++)
        if (a[j] == (s[i][j] - '0')) Lik++;
      if (Lik != like[i]) return false;
    }
  }
  return true;
}
void attempt(int i, int same) {
  if (i == n) {
    if (same == like[1] && Check_Res() == true) {
      T_res++;
    }
    return;
  }
  a[i] = !((s[1][i]) - '0');
  attempt(i + 1, same);
  if (same < like[1]) {
    a[i] = (s[1][i] - '0');
    attempt(i + 1, same + 1);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    cin >> s[i];
    cin >> like[i];
  }
  attempt(0, 0);
  cout << T_res;
}
