#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 + 20;
template <class t>
ostream &operator<<(ostream &tout, const vector<t> &s) {
  tout << '[';
  for (int i = 0; i < s.size(); i++)
    if (i + 1 == s.size())
      tout << s[i];
    else
      tout << s[i] << ',';
  tout << ']';
  return (tout);
}
string num[MAX_N];
int __fuck__[MAX_N], n;
int same(string s, string t) {
  int ans = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == t[i]) ans++;
  return (ans);
}
int main() {
  cin >> n >> n;
  for (int i = 1; i <= n; i++) cin >> num[i] >> __fuck__[i];
  vector<bool> temp(num[1].size());
  for (int i = 0; i < __fuck__[1]; i++) temp[i] = true;
  reverse(temp.begin(), temp.end());
  vector<string> results;
  do {
    string res = "";
    for (int i = 0; i < temp.size(); i++)
      if (temp[i])
        res += num[1][i];
      else
        res += num[1][i] ^ 1;
    results.push_back(res);
  } while (next_permutation(temp.begin(), temp.end()));
  int ans = 0;
  for (int i = 0; i < results.size(); i++) {
    bool bad = false;
    for (int j = 1; j <= n && !bad; j++)
      if (same(results[i], num[j]) != __fuck__[j]) bad = true;
    if (!bad) ans++;
  }
  cout << ans << endl;
}
