#include <bits/stdc++.h>
using namespace std;
struct Node {
  string s;
  int d;
} a[10];
int n, m, ans;
bool operator<(Node x, Node y) { return x.d < y.d; }
void dfs(int p, int k, string str) {
  if (p == n) {
    for (int i = 1; i < m; ++i) {
      k = 0;
      for (int j = 0; j < n; ++j) k += str[j] == a[i].s[j];
      if (k != a[i].d) return;
    }
    ++ans;
    return;
  }
  if (k < a[0].d) dfs(p + 1, k + 1, str + a[0].s[p]);
  if (a[0].d - k <= n - 1 - p) dfs(p + 1, k, str + char(97 - a[0].s[p]));
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) cin >> a[i].s >> a[i].d;
  sort(a, a + m);
  ans = 0;
  dfs(0, 0, "");
  cout << ans << endl;
  return 0;
}
