#include <bits/stdc++.h>
using namespace std;
char attempt[10][36], right1[36];
int n, m, ans = 0, test[10], om;
bool cheak() {
  int k;
  for (int i = 0; i < m; ++i) {
    k = 0;
    for (int j = 0; j < n; ++j) {
      if (attempt[i][j] == right1[j]) ++k;
    }
    if (k != test[i]) return false;
  }
  return true;
}
void solve(int j) {
  if (j == n) {
    if (cheak()) ++ans;
    return;
  }
  if (om > 0) {
    right1[j] = attempt[0][j];
    --om;
    solve(j + 1);
    ++om;
  }
  right1[j] = attempt[0][j] == '0' ? '1' : '0';
  solve(j + 1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) scanf("%s%d", attempt[i], &test[i]);
  om = test[0];
  solve(0);
  cout << ans;
  return 0;
}
