#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > zb;
void gen(vector<int>& a, int nr, int x, int maxi, int dl) {
  a[nr] = x;
  if (nr == dl - 1) {
    zb.push_back(a);
    return;
  }
  for (int i = x + 1; i < maxi; ++i) gen(a, nr + 1, i, maxi, dl);
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<string> sl(m);
  vector<int> db(m);
  for (int i = 0; i < m; ++i) cin >> sl[i] >> db[i];
  int odp = 0;
  if (db[0] != 0) {
    vector<int> z(db[0]);
    for (int i = 0; i < n; ++i) gen(z, 0, i, n, db[0]);
  } else {
    vector<int> z;
    zb.push_back(z);
  }
  for (int i = 0; i < zb.size(); ++i) {
    string t = sl[0];
    vector<bool> ok(n, false);
    for (int j = 0; j < zb[i].size(); ++j) ok[zb[i][j]] = true;
    for (int j = 0; j < n; ++j) {
      if (!ok[j]) {
        if (t[j] == '0')
          t[j] = '1';
        else
          t[j] = '0';
      }
    }
    bool moze = true;
    for (int j = 1; j < m; ++j) {
      int same = 0;
      for (int k = 0; k < n; ++k)
        if (sl[j][k] == t[k]) ++same;
      if (same != db[j]) moze = false;
    }
    if (moze) ++odp;
  }
  cout << odp;
  return 0;
}
