#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[1005];
vector<long long> v, w;
void go(int x, long long t, int r) {
  if (x == n) {
    if (r == 0) w.push_back(t);
  } else {
    go(x + 1, t * 2 + 1 - (s[x] - '0'), r);
    if (r) go(x + 1, t * 2 + s[x] - '0', r - 1);
  }
}
void merge(int f) {
  if (!f) {
    v = w;
    sort(v.begin(), v.end());
  } else {
    vector<long long> a;
    sort(w.begin(), w.end());
    int j = 0;
    for (int i = 0; i < (int)w.size(); i++) {
      while (j < (int)v.size() && v[j] < w[i]) ++j;
      if (j < (int)v.size() && v[j] == w[i]) a.push_back(v[j]);
    }
    v = a;
  }
}
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int d;
    scanf("%s%d", s, &d);
    w.clear();
    go(0, 0, d);
    merge(i);
  }
  printf("%d\n", (int)v.size());
  return 0;
}
