#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e9;
const int N = 2 * 1e5 + 5;
const double eps = 1e-5;
string s[20], a;
int n, m, ans = 0, c[20];
void solve(int i, int k) {
  if (i == n) {
    if (k == 0) {
      int x;
      for (int j = 1; j < m; j++) {
        x = 0;
        for (int t = 0; t < n; t++)
          if (a[t] == s[j][t]) x++;
        if (x != c[j]) return;
      }
      ans++;
    }
    return;
  }
  a[i] = '0';
  if (s[0][i] == '0') {
    if (k > 0) solve(i + 1, k - 1);
  } else
    solve(i + 1, k);
  a[i] = '1';
  if (s[0][i] == '1') {
    if (k > 0) solve(i + 1, k - 1);
  } else
    solve(i + 1, k);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  a = "";
  for (int i = 0; i < n; i++) a += '0';
  solve(0, c[0]);
  cout << ans << endl;
}
