#include <bits/stdc++.h>
using namespace std;
string serial;
string TrialSerial;
string num;
int finalCounter = 0;
int n, m, correctPlaces;
string workingSerials[400000];
int putCounter = 0;
int workingTest() {
  if (TrialSerial.length() <= 0) return 0;
  if (TrialSerial.length() != serial.length()) return 0;
  int counter = 0;
  for (int i = 0; i < n; ++i) {
    if (TrialSerial[i] != serial[i]) {
      if (TrialSerial[i] == '0' || TrialSerial[i] == '1') counter++;
    }
  }
  return counter;
}
void combine(int index, int max, int correctPlaces) {
  string Mask;
  Mask.clear();
  for (int i = 0; i < n; i++) {
    if (i < correctPlaces)
      Mask += "1";
    else
      Mask += "0";
  }
  sort(Mask.begin(), Mask.end());
  do {
    for (int i = 0; i < n; ++i) {
      if (Mask[i] == '1') {
        if (serial[i] == '1')
          TrialSerial.replace(i, 1, "1");
        else
          TrialSerial.replace(i, 1, "0");
      } else {
        if (serial[i] == '1') {
          TrialSerial.replace(i, 1, "0");
        } else
          TrialSerial.replace(i, 1, "1");
      }
    }
    if (workingTest() == (n - correctPlaces)) {
      workingSerials[putCounter++] = TrialSerial;
    }
  } while (next_permutation(Mask.begin(), Mask.end()));
}
int main(int argc, char const *argv[]) {
  for (int i = 0; i < 400000; ++i) {
    workingSerials[i].clear();
  }
  scanf("%d %d", &n, &m);
  int mtmp = m;
  TrialSerial.clear();
  serial.clear();
  cin >> serial >> correctPlaces;
  combine(0, n, correctPlaces);
  mtmp--;
  while (mtmp--) {
    correctPlaces = 0;
    scanf("%s %d", serial.begin(), &correctPlaces);
    for (int i = 0; i < putCounter; ++i) {
      TrialSerial = workingSerials[i];
      if (workingTest() != (n - correctPlaces)) {
        workingSerials[i].clear();
      }
    }
  }
  int resCounter = 0;
  for (int i = 0; i < 400000; ++i) {
    if (workingSerials[i].length() > 0) resCounter++;
  }
  printf("%d\n", resCounter);
  return 0;
}
