#include <bits/stdc++.h>
using namespace std;
map<string, int> M[2];
int n, m, k, i;
string s;
void f(int k, int tip, int ind) {
  if (k == 0) {
    if (M[1 - (i % 2)][s] == 1 || tip == 0) M[i % 2][s] = 1;
    return;
  }
  for (int j = ind; j <= (s.size() - k); j++) {
    s[j] = 1 - (s[j] - '0') + '0';
    f(k - 1, tip, j + 1);
    s[j] = 1 - (s[j] - '0') + '0';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  cin >> s >> k;
  i = 1;
  f(k, 0, 0);
  for (i = 2; i <= m; i++) {
    M[i % 2].clear();
    cin >> s >> k;
    f(k, 1, 0);
  }
  cout << M[m % 2].size();
  return 0;
}
