#include <bits/stdc++.h>
using namespace std;
int ans = 0;
char tmp[36];
string s[11];
int min_tr = 6;
int ind = -1;
bool NextSet(int *a, int n, int m) {
  int k = m;
  for (int i = k - 1; i >= 0; --i)
    if (a[i] < n - k + i + 1) {
      ++a[i];
      for (int j = i + 1; j < k; ++j) a[j] = a[j - 1] + 1;
      for (int i = 0; i < k; ++i) tmp[a[i] - 1] = s[ind][a[i] - 1];
      return true;
    }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  int tr[11];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> tr[i];
    if (tr[i] < min_tr) {
      min_tr = tr[i];
      ind = i;
    }
  }
  for (int i = 0; i < s[ind].length(); ++i)
    if (s[ind][i] == '0')
      tmp[i] = '1';
    else
      tmp[i] = '0';
  int *a = new int[min_tr];
  for (int i = 0; i < min_tr; i++) {
    a[i] = i + 1;
    tmp[a[i] - 1] = s[ind][a[i] - 1];
  }
  int cnt = 0;
  for (int w = 0; w < m; ++w) {
    int cur = 0;
    if (w != ind) {
      for (int e = 0; e < s[w].length(); ++e)
        if (tmp[e] == s[w][e]) cur++;
    }
    if (cur == tr[w]) cnt++;
  }
  if (cnt == m - 1) ans++;
  for (int i = 0; i < s[ind].length(); ++i)
    if (s[ind][i] == '0')
      tmp[i] = '1';
    else
      tmp[i] = '0';
  while (NextSet(a, n, min_tr)) {
    int cnt = 0;
    for (int w = 0; w < m; ++w) {
      int cur = 0;
      if (w != ind) {
        for (int e = 0; e < s[w].length(); ++e)
          if (tmp[e] == s[w][e]) cur++;
      }
      if (cur == tr[w]) cnt++;
    }
    if (cnt == m - 1) ans++;
    for (int i = 0; i < s[ind].length(); ++i)
      if (s[ind][i] == '0')
        tmp[i] = '1';
      else
        tmp[i] = '0';
  }
  cout << ans;
  return 0;
}
