#include <bits/stdc++.h>
int n, m;
std::vector<std::pair<std::string, short> > attempts;
short c = std::numeric_limits<short>::max();
short taken;
std::string currPass;
int result;
bool check() {
  bool success = true;
  short currRes;
  for (int i = 1; i < m; i++) {
    currRes = 0;
    for (int j = 0; j < n; j++) {
      if (attempts[i].first[j] == currPass[j]) {
        ++currRes;
      }
    }
    if (currRes != attempts[i].second) {
      success = false;
      break;
    }
  }
  return success;
}
void generate(short idx) {
  if (taken == c) {
    if (check()) {
      ++result;
    }
    return;
  }
  for (int i = idx; i < n; i++) {
    currPass[i] = attempts[0].first[i];
    ++taken;
    generate(i + 1);
    currPass[i] = 97 - attempts[0].first[i];
    --taken;
  }
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  short attemptIdx;
  std::cin >> n >> m;
  attempts.resize(m);
  for (int i = 0; i < m; i++) {
    std::cin >> attempts[i].first >> attempts[i].second;
    if (attempts[i].second < c) {
      c = attempts[i].second;
      attemptIdx = i;
    }
  }
  std::swap(attempts[0], attempts[attemptIdx]);
  for (int i = 0; i < n; i++) {
    currPass.push_back(97 - attempts[0].first[i]);
  }
  generate(0);
  std::cout << result << '\n';
  return 0;
}
