#include <bits/stdc++.h>
using namespace std;
map<vector<int>, long long> cur, nxt;
int n, m;
string s[11];
int num[11];
int main() {
  cin >> n >> m;
  vector<int> beg(m);
  for (int(i) = 0; (i) < (m); ++(i)) cin >> s[i] >> beg[i];
  cur[beg] = 1;
  for (int(i) = 0; (i) < (n); ++(i)) {
    nxt.clear();
    for (map<vector<int>, long long>::iterator it = cur.begin();
         it != cur.end(); ++it) {
      vector<int> now = it->first;
      vector<int> pos = now;
      for (int(let) = 0; (let) < (2); ++(let)) {
        pos = now;
        bool ok = 1;
        for (int(j) = 0; (j) < (m); ++(j)) {
          if (s[j][i] == '0' + let) pos[j]--;
          if (pos[j] < 0) {
            ok = 0;
            break;
          }
        }
        if (ok) nxt[pos] += it->second;
      }
    }
    cur = nxt;
  }
  cout << cur[vector<int>(m, 0)] << endl;
}
