#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0;
vector<pair<string, int> > vsi;
char opp(char c) { return (c == '0') ? '1' : '0'; }
vector<int> te;
void btrk(int sz, int prev) {
  if (sz == vsi[0].second) {
    string s = vsi[0].first;
    int ptr = 0;
    for (int i = 0; n > i; i++) {
      if (te[ptr] != i)
        s[i] = opp(s[i]);
      else
        ptr++;
    }
    bool b = true;
    int cur = 0;
    for (int i = 1; m > i; i++) {
      cur = 0;
      for (int j = 0; n > j; j++) cur += (s[j] == vsi[i].first[j]);
      if (cur != vsi[i].second) return;
    }
    ans++;
  } else {
    for (int i = prev + 1; n > i; i++) {
      te.push_back(i);
      btrk(sz + 1, i);
      te.pop_back();
    }
  }
}
int main() {
  cin >> n >> m;
  vsi.resize(m);
  for (int i = 0; m > i; i++) cin >> vsi[i].first >> vsi[i].second;
  btrk(0, -1);
  printf("%d\n", ans);
}
