#include <bits/stdc++.h>
using namespace std;
char arr[15][40];
bool trr[40];
int counter;
char answer[40];
int correct[40];
int siz, num;
void combin(int siz, int num, int index, int r, int d, int z);
void solve();
int main() {
  int mi = INT_MAX, index = 0;
  scanf("%d %d", &siz, &num);
  getchar();
  for (int i = 0; i < num; i++) {
    for (int j = 0; j < siz; j++) {
      scanf("%c", &arr[i][j]);
    }
    scanf("%d", &correct[i]);
    getchar();
    if (correct[i] < mi) {
      index = i;
      mi = correct[i];
    }
  }
  combin(siz, num, index, 0, mi, 0);
  printf("%d", counter);
  return 0;
}
void combin(int siz, int num, int index, int r, int d, int z) {
  if (r == d) {
    for (int i = 0; i < siz; i++) {
      if (trr[i])
        answer[i] = arr[index][i];
      else if (arr[index][i] == '0')
        answer[i] = '1';
      else
        answer[i] = '0';
    }
    solve();
    return;
  }
  for (int i = z; i < siz; i++) {
    trr[i] = true;
    combin(siz, num, index, r + 1, d, i + 1);
    trr[i] = false;
  }
  return;
}
void solve() {
  bool flag = true;
  int smallcount = 0;
  for (int i = 0; i < num; i++) {
    smallcount = 0;
    for (int j = 0; j < siz; j++) {
      if (arr[i][j] == answer[j]) {
        smallcount++;
      }
      if (smallcount > correct[i]) {
        return;
      }
    }
    if (smallcount != correct[i]) return;
  }
  counter++;
  return;
}
