#include <bits/stdc++.h>
using namespace std;
int n, m, cor[12];
int a[12][40], now[40];
long long ans;
void dfs(int pos, int lv) {
  if (pos == n) {
    bool flag = true;
    for (int i = 1; i < m; i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++)
        if (a[i][j] == now[j]) cnt++;
      if (cnt != cor[i]) {
        flag = false;
        break;
      }
    }
    if (flag) ans++;
  } else {
    if (n - 1 - pos >= lv) {
      now[pos] = !a[0][pos];
      dfs(pos + 1, lv);
    }
    if (lv) {
      now[pos] = a[0][pos];
      dfs(pos + 1, lv - 1);
    }
  }
}
int main() {
  char str[40];
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < m; i++) {
      scanf("%s%d", str, cor + i);
      for (int j = 0; j < n; j++) a[i][j] = str[j] - '0';
    }
    ans = 0;
    dfs(0, cor[0]);
    cout << ans << endl;
  }
  return 0;
}
