#include <bits/stdc++.h>
using namespace std;
const int maxn = 40;
int n, m, c[maxn], ans;
string s[maxn];
void bt(int pos, int cnt, string cur) {
  if (pos == n) {
    if (cnt != 0) return;
    for (int i = 2; i <= m; i++) {
      int res = 0;
      for (int j = 0; j < n; j++)
        if (cur[j] == s[i][j]) res++;
      if (res != c[i]) return;
    }
    ans++;
    return;
  }
  char now = s[1][pos];
  if (cnt) bt(pos + 1, cnt - 1, cur + now);
  if (now == '1')
    now = '0';
  else
    now = '1';
  bt(pos + 1, cnt, cur + now);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> s[i] >> c[i];
  string tmp = "";
  bt(0, c[1], tmp);
  cout << ans << endl;
  return 0;
}
