#include <bits/stdc++.h>
using namespace std;
const int N = 1e8 + 5, OO = 2e9, MOD = 1e9 + 7;
double EPS = 1e-9;
int TC, n, t;
string s, cur;
int m;
unordered_set<string> st;
void solve(int pos, int x) {
  if (x == m) {
    string tmp = cur;
    while (tmp.size() < n) tmp += s[tmp.size()] == '0' ? '1' : '0';
    st.insert(tmp);
  } else if (n - pos == m - x) {
    string tmp = cur;
    while (tmp.size() < n) tmp += s[tmp.size()];
    st.insert(tmp);
  } else {
    if (pos == n) return;
    cur += s[pos];
    solve(pos + 1, x + 1);
    cur.pop_back();
    if (n - pos >= m - x) {
      cur += s[pos] == '0' ? '1' : '0';
      solve(pos + 1, x);
      cur.pop_back();
    }
  }
}
int main() {
  auto bef = clock();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  unordered_set<string> curst;
  cin >> n >> TC;
  for (int i = 0; i < TC; ++i) {
    cin >> s >> m;
    solve(0, 0);
    if (i == 0)
      for (auto &z : st) curst.insert(z);
    else {
      unordered_set<string> tmp;
      for (auto &z : st)
        if (curst.find(z) != curst.end()) tmp.insert(z);
      tmp.swap(curst);
    }
    st.clear();
  }
  cout << curst.size() << '\n';
  cerr << fixed << setprecision(10) << (clock() - bef - 0.0) / CLOCKS_PER_SEC;
  return 0;
}
