#include <bits/stdc++.h>
using namespace std;
const long long N = 40;
long long n, m;
string s[40];
long long r[40];
long long ans = 0;
void deal(long long idx) {
  for (long long i = 0; i < m; i++)
    if (r[i] < 0) return;
  if (idx == n) {
    for (long long i = 0; i < m; i++)
      if (r[i] != 0) return;
    ans++;
    return;
  }
  for (long long j = 0; j <= 1; j++) {
    for (long long i = 0; i < m; i++) {
      if (s[i][idx] - '0' == j) r[i]--;
    }
    deal(idx + 1);
    for (long long i = 0; i < m; i++) {
      if (s[i][idx] - '0' == j) r[i]++;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) cin >> s[i] >> r[i];
  deal(0);
  cout << ans;
}
