#include <bits/stdc++.h>
using namespace std;
ifstream fin("INPUT.txt");
ofstream fout("OUTPUT.txt");
const int N = 37;
const long M = 13;
const long long INF = 1000000000000000000;
int mod = 1000000007;
int n, m, k, suc = false;
int Count = 0, d[M] = {0}, a[M] = {0};
string s[M];
void F(int k) {
  if (k > n - 1) {
    for (int i = 0; i < m; i++)
      if (d[i] != a[i]) return;
    Count++;
    return;
  }
  for (int i = 0; i < m; i++)
    if (d[i] > a[i]) return;
  for (int i = 0; i < m; i++)
    if (s[i][k] == '0') d[i]++;
  F(k + 1);
  for (int i = 0; i < m; i++)
    if (s[i][k] == '0')
      d[i]--;
    else
      d[i]++;
  F(k + 1);
  for (int i = 0; i < m; i++)
    if (s[i][k] == '1') d[i]--;
}
int main() {
  ios::sync_with_stdio(false);
  cout.precision(10);
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> a[i];
  F(0);
  cout << Count << endl;
  return 0;
}
