#include <bits/stdc++.h>
using namespace std;
string s[15];
string aux;
int correct[15];
int n, m;
long long res;
void dfs(int cur, int start, int remain) {
  if (cur == m) {
    res++;
    return;
  }
  if (!cur) {
    if (remain) {
      if (start == n) return;
      dfs(cur, start + 1, remain);
      aux[start] = s[cur][start];
      dfs(cur, start + 1, remain - 1);
      aux[start] = '.';
    } else {
      string tmp = aux;
      for (int i = 0; i < n; ++i)
        if (aux[i] == '.') aux[i] = s[cur][i] == '1' ? '0' : '1';
      dfs(cur + 1, 0, correct[cur + 1]);
      aux = tmp;
    }
  } else {
    int cnt = 0;
    for (int i = 0; i < n; ++i)
      if (aux[i] == s[cur][i]) cnt++;
    if (cnt == remain) dfs(cur + 1, 0, correct[cur + 1]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) cin >> s[i] >> correct[i];
  for (int i = 0; i < n; ++i) aux.push_back('.');
  res = 0;
  dfs(0, 0, correct[0]);
  cout << res << endl;
}
