#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:836777216")
using namespace std;
int n, m;
string ask[10];
int match[10];
char s[40];
map<int, int> cnt;
int main(void) {
  scanf("%d%d", &n, &m);
  for (int(i) = 0; (i) < (m); (i)++) {
    scanf("%s", &s);
    ask[i] = (string)s;
    scanf("%d", &match[i]);
  }
  for (int(i) = 0; (i) < ((1 << (n / 2))); (i)++) {
    int cur = 0;
    int mn = 6;
    for (int(j) = 0; (j) < (m); (j)++) {
      int ans = 0;
      for (int(k) = 0; (k) < (n / 2); (k)++) {
        if (i & (1 << (k))) {
          if (ask[j][k] == '1') {
            ans++;
          }
        } else {
          if (ask[j][k] == '0') {
            ans++;
          }
        }
      }
      if (ans <= match[j]) {
        cur *= mn;
        cur += ans;
      } else {
        cur = -1;
        break;
      }
    }
    if (cur != -1) cnt[cur]++;
  }
  long long result = 0;
  for (int(i) = 0; (i) < ((1 << (n / 2 + n % 2))); (i)++) {
    int cur = 0;
    int mn = 6;
    for (int(j) = 0; (j) < (m); (j)++) {
      int ans = 0;
      for (int(k) = 0; (k) < ((n / 2 + n % 2)); (k)++) {
        if (i & (1 << (k))) {
          if (ask[j][k + n / 2] == '1') {
            ans++;
          }
        } else {
          if (ask[j][k + n / 2] == '0') {
            ans++;
          }
        }
      }
      if (ans > match[j]) {
        cur = -1;
        break;
      } else {
        cur *= mn;
        cur += (match[j] - ans);
      }
    }
    if (cur != -1) {
      result += (long long)cnt[cur];
    }
  }
  printf("%lld\n", result);
  return 0;
}
