#include <bits/stdc++.h>
using namespace std;
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int N = 36;
string s[N];
int c[N], n, m;
int solve(int idx) {
  if (idx == n) {
    for (int i = 0; i < m; i++)
      if (c[i] != 0) return 0;
    return 1;
  }
  int rt = 0;
  for (int one = 0; one < 2; one++) {
    bool valid = true;
    for (int i = 0; i < m; i++) {
      if (s[i][idx] - '0' == one) c[i]--;
      if (c[i] < 0) valid = false;
    }
    if (valid) rt += solve(idx + 1);
    for (int i = 0; i < m; i++)
      if (s[i][idx] - '0' == one) c[i]++;
  }
  return rt;
}
int main() {
  run();
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  cout << solve(0) << "\n";
}
