#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
string s[maxn];
int cur[maxn], c[maxn];
int n, m, ans = 0;
void dfs(int x) {
  if (x == n) {
    int flag = 1;
    for (int i = 1; i <= m; i++)
      if (cur[i] - c[i]) flag = 0;
    ans += flag;
    return;
  }
  for (char v = '0'; v <= '1'; v++) {
    int can = 1;
    for (int i = 1; i <= m; i++) {
      cur[i] += (v == s[i][x]);
      if (cur[i] > c[i]) can = 0;
    }
    if (can) dfs(x + 1);
    for (int i = 1; i <= m; i++) cur[i] -= (v == s[i][x]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> s[i] >> c[i];
  memset(cur, 0, sizeof(cur));
  dfs(0);
  cout << ans << endl;
  return 0;
}
