#include <bits/stdc++.h>
using namespace std;
const int MAX_M = 10 + 2, MAX_N = 35;
int n, m, c[MAX_M];
string s[MAX_M];
vector<vector<int>> cpos;
bool check(const string& exp, const string& other, const int match) {
  int cnt = 0;
  for (int i = 0; i < n; i++) cnt += (exp[i] == other[i]);
  return cnt == match;
}
int solve() {
  int ans = 0;
  for (auto correct : cpos) {
    string exp = s[0];
    for (int i = 0; i < exp.size(); i++) exp[i] = (exp[i] == '1') ? '0' : '1';
    for (auto p : correct) exp[p] = (exp[p] == '1') ? '0' : '1';
    bool ok = true;
    for (int k = 0; k < m; k++) ok &= check(exp, s[k], c[k]);
    ans += ok;
  }
  return ans;
}
vector<int> add;
void generate(int pos, int cnt) {
  if (cnt == 0) {
    cpos.push_back(add);
    return;
  }
  if (pos == n) return;
  add.push_back(pos);
  generate(pos + 1, cnt - 1);
  add.pop_back();
  generate(pos + 1, cnt);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin.ignore();
    cin >> s[i] >> c[i];
  }
  cpos.push_back({});
  if (c[0]) generate(0, c[0]);
  cout << solve() << endl;
  return (0);
}
