#include <bits/stdc++.h>
using namespace std;
const int Nmax = 47;
int n, m;
string s[47];
int c[47], x[47];
int res;
void attempt(int i, int same) {
  if (i == n) {
    if (same != c[1]) return;
    string b;
    for (int j = 0; j < n; j++) b += (char)x[j] + '0';
    int Count = 1;
    for (int j = 2; j <= m; j++) {
      int dem = 0;
      for (int k = 0; k < n; k++) dem += (s[j][k] == b[k]);
      Count += (dem == c[j]);
    }
    res += (Count == m);
    return;
  }
  x[i] = (int)!(s[1][i] - '0');
  attempt(i + 1, same);
  if (same < c[1]) {
    x[i] = (int)s[1][i] - '0';
    attempt(i + 1, same + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  attempt(0, 0);
  cout << res;
  return 0;
}
