#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int ans = 0, n, m, cnt[11], arr[11];
vector<string> v;
void solve(int idx) {
  if (idx >= n) {
    for (int i = 0; i <= m - 1; ++i) {
      if (cnt[i] != arr[i]) return;
    }
    ++ans;
    return;
  }
  bool is = true;
  for (int i = 0; i < m; ++i) {
    if (v[i][idx] == '1') cnt[i]++;
    if (cnt[i] > arr[i]) is = false;
  }
  if (is) solve(idx + 1);
  for (int i = 0; i < m; ++i) {
    if (v[i][idx] == '1') cnt[i]--;
  }
  is = true;
  for (int i = 0; i < m; ++i) {
    if (v[i][idx] == '0') cnt[i]++;
    if (cnt[i] > arr[i]) is = false;
  }
  if (is) solve(idx + 1);
  for (int i = 0; i < m; ++i) {
    if (v[i][idx] == '0') cnt[i]--;
  }
}
int main() {
  ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  ;
  cin >> n >> m;
  v.resize(m + 1);
  for (int i = 0; i <= m - 1; ++i) cin >> v[i] >> arr[i];
  solve(0);
  cout << ans << "\n";
  return 0;
}
