#include <bits/stdc++.h>
using namespace std;
const int MXN = 35;
const int MXM = 10;
int N, M;
string str[MXM];
int cnt[MXM];
bool ok(int d) {
  for (int i = 0; i < M; ++i) {
    if (cnt[i] < 0 || cnt[i] > N - d) {
      return false;
    }
  }
  return true;
}
int geth(int d) {
  int h = 0;
  for (int i = 0; i < M; ++i) {
    h = h * 6 + cnt[i];
  }
  return h * 40 + d;
}
map<int, long long> mem;
long long dp(int d) {
  if (!ok(d)) {
    return 0;
  }
  if (d == N) {
    return 1;
  }
  int h = geth(d);
  map<int, long long>::iterator it = mem.find(h);
  if (it != mem.end()) {
    return it->second;
  }
  long long &res = mem[h];
  for (char i = '0'; i <= '1'; ++i) {
    for (int j = 0; j < M; ++j) {
      if (i == str[j][d]) {
        cnt[j]--;
      }
    }
    res += dp(d + 1);
    for (int j = 0; j < M; ++j) {
      if (i == str[j][d]) {
        cnt[j]++;
      }
    }
  }
  return res;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    cin >> str[i] >> cnt[i];
  }
  cout << dp(0);
}
