#include <bits/stdc++.h>
double const PI = 4 * atan(1.0);
using namespace std;
string s[111], S;
int correct[111], n, m, f[6];
bool ketthuc() {
  for (int i = 0; i < correct[1]; i++)
    if (f[i] != n - correct[1] + i) return false;
  return true;
}
bool chinhxac(int x) {
  int res = 0;
  for (int i = 0; i < n; i++)
    if (S[i] == s[x][i]) res++;
  return (res == correct[x]);
}
void tangvong() {
  if (f[correct[1] - 1] < n - 1)
    f[correct[1] - 1]++;
  else
    for (int i = correct[1] - 2; i >= 0; i--) {
      if (f[i] + 1 != f[i + 1]) {
        f[i]++;
        for (int j = i + 1; j < correct[1]; j++) f[j] = f[i] + j - i;
        break;
      }
    }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> correct[i];
  }
  int kq = 0;
  for (int i = 0; i < correct[1]; i++) f[i] = i;
  int run = 0;
  while (true) {
    bool check = true;
    S = "";
    for (int i = 0; i < n; i++) S += '1' - s[1][i] + '0';
    for (int i = 0; i < correct[1]; i++) S[f[i]] = '1' + '0' - S[f[i]];
    for (int i = 2; i <= m; i++)
      if (!chinhxac(i)) {
        check = false;
        break;
      }
    if (check) kq++;
    if (ketthuc()) break;
    tangvong();
  }
  printf("%d", kq);
}
