#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int n, m, c;
string s;
bool x = true;
void bk(int i, int r) {
  if (r == 0) {
    if (x)
      mp[s]++;
    else if (mp.find(s) != mp.end())
      mp[s]++;
    return;
  }
  if (i == n) return;
  for (int j = i; j < n; ++j) {
    if (s[j] == '0') {
      s[j] = '1';
      bk(j + 1, r - 1);
      s[j] = '0';
    } else {
      s[j] = '0';
      bk(j + 1, r - 1);
      s[j] = '1';
    }
  }
}
void inv() {
  for (auto &i : s) {
    if (i == '1')
      i = '0';
    else
      i = '1';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> s >> c;
  if (c > n - c)
    c = n - c;
  else
    inv();
  bk(0, c);
  x = 0;
  for (int i = 1; i < m; i++) {
    cin >> s >> c;
    if (c > n - c)
      c = n - c;
    else
      inv();
    bk(0, c);
  }
  int cnt = 0;
  for (auto &i : mp) {
    if (i.second == m) cnt++;
  }
  cout << cnt;
  return 0;
}
