#include <bits/stdc++.h>
using namespace std;
const int MAXM = 11;
vector<long long> v, temv;
long long a[MAXM];
int ccnt[MAXM];
int n, m;
void DFS(int k, int rest, long long num) {
  if (k == n) {
    if (rest == 0) v.push_back(num);
    return;
  }
  if (rest > 0) DFS(k + 1, rest - 1, num + (a[0] & ((long long)1 << k)));
  DFS(k + 1, rest, num + ((a[0] & ((long long)1 << k)) ^ ((long long)1 << k)));
  return;
}
int Count(long long a, long long b) {
  int ret = 0;
  for (int i = 0; i < n; i++)
    if ((a & ((long long)1 << i)) == (b & ((long long)1 << i))) ret++;
  return ret;
}
int main() {
  string st;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> st >> ccnt[i];
    for (int j = 0; j < n; j++) a[i] <<= 1, a[i] += st[j] - '0';
  }
  DFS(0, ccnt[0], (long long)0);
  for (int i = 1; i < m; i++) {
    temv.clear();
    for (vector<long long>::iterator iter = v.begin(); iter != v.end(); iter++)
      if (Count(*iter, a[i]) == ccnt[i]) temv.push_back(*iter);
    v = temv;
  }
  cout << v.size() << endl;
  return 0;
}
