#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int N = (1 << 18);
const long long OO = (long long)1 * 1e18;
const long long mod = 1e9 + 7;
int n, m, a[10];
vector<string> x, v(10);
void go(string h, int t) {
  if (h.size() == n) {
    if (t == a[0]) x.push_back(h);
    return;
  }
  int y = (v[0][h.size()] - '0');
  if (t < a[0]) go(h + (char)(y + '0'), t + 1);
  if (n + t >= a[0] + h.size()) go(h + (char)(1 - y + '0'), t);
}
bool match(string r, int u) {
  int s = 0;
  for (int i = 0; i < n; i++)
    if (r[i] == v[u][i])
      if (++s > a[u]) return 0;
  if (s == a[u]) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> v[i] >> a[i];
  go("", 0);
  for (int i = 1; i < m; i++) {
    vector<string> t = x;
    x = vector<string>();
    for (auto it : t)
      if (match(it, i)) x.push_back(it);
  }
  cout << x.size();
  return 0;
}
