#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > ac;
vector<int> tc;
int n, m;
void gc(int id, int in) {
  if (!id) {
    ac.push_back(tc);
    return;
  }
  for (int i = in; i <= n - id; i++) {
    tc.push_back(i);
    gc(id - 1, i + 1);
    tc.pop_back();
  }
}
int main() {
  cin >> n >> m;
  vector<string> ms(m);
  vector<int> mc(m);
  for (int i = 0; i < m; i++) cin >> ms[i] >> mc[i];
  gc(mc[0], 0);
  int anw = 0;
  for (vector<int> &b : ac) {
    string c = ms[0];
    for (int i = 0; i < n; i++) c[i] = (c[i] == '0' ? '1' : '0');
    for (int &p : b) c[p] = ms[0][p];
    bool f = 1;
    for (int i = 1; i < m; i++) {
      int r = 0;
      for (int j = 0; j < n; j++) {
        if (ms[i][j] == c[j]) r++;
      }
      if (mc[i] != r) {
        f = 0;
        break;
      }
    }
    if (f) anw++;
  }
  cout << anw << endl;
}
