#include <bits/stdc++.h>
using namespace std;
struct iii {
  int a, b, c;
  iii() {}
  iii(int a, int b, int c) : a(a), b(b), c(c) {}
  bool operator<(const iii& e) const {
    return a < e.a || a == e.a && (b < e.b || b == e.b && c < e.c);
  }
};
struct Scanner {
  Scanner& operator>>(int& x) {
    scanf("%d", &x);
    return *this;
  }
  Scanner& operator>>(double& x) {
    scanf("%lf", &x);
    return *this;
  }
  Scanner& operator>>(char* x) {
    scanf("%s", x);
    return *this;
  }
  Scanner& operator>>(long long& x) {
    scanf("%I64d", &x);
    return *this;
  }
  Scanner& operator>>(pair<int, int>& x) {
    scanf("%d%d", &x.first, &x.second);
    return *this;
  }
  Scanner& operator>>(pair<double, double>& x) {
    scanf("%lf%lf", &x.first, &x.second);
    return *this;
  }
} in;
template <typename T>
T sq(const T& x) {
  return x * x;
}
template <typename T>
void minl(T& a, const T& b) {
  if (a > b) a = b;
}
template <typename T>
void maxl(T& a, const T& b) {
  if (a < b) a = b;
}
template <typename T>
void usort(vector<T>& a) {
  sort((a).begin(), (a).end());
  a.erase(unique((a).begin(), (a).end()), a.end());
}
template <typename T>
int index(const vector<T>& a, const T& x) {
  return lower_bound((a).begin(), (a).end(), x) - a.begin();
}
template <typename T>
void operator+=(vector<T>& a, const T& x) {
  a.push_back(x);
}
template <typename T>
void operator+=(set<T>& a, const T& x) {
  a.insert(x);
}
template <typename T>
bool operator&(const set<T>& a, const T& x) {
  return a.find(x) != a.end();
}
pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {
  return pair<int, int>(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(const pair<int, int>& a, const pair<int, int>& b) {
  return pair<int, int>(a.first - b.first, a.second - b.second);
}
long long cross(const pair<int, int>& a, const pair<int, int>& b) {
  return (long long)a.first * b.second - (long long)b.first * a.second;
}
long long dot(const pair<int, int>& a, const pair<int, int>& b) {
  return (long long)a.first * b.first + (long long)a.second * b.second;
}
int bitcnt(unsigned x) { return __builtin_popcount(x); }
int bitlow(unsigned x) { return __builtin_ffs(x); }
int n, m;
char s[10][36];
int bingo[10];
char a[35];
int ans;
bool check() {
  for (int i = 0; i < (m); ++i) {
    if (i == 0) continue;
    int c = 0;
    for (int j = 0; j < (n); ++j) c += a[j] == s[i][j];
    if (c != bingo[i]) return false;
  }
  return true;
}
void _(int p, int c) {
  if (c > bingo[0]) return;
  if (p >= n) {
    if (c == bingo[0] && check()) ans++;
    return;
  }
  a[p] = s[0][p];
  _(p + 1, c + 1);
  a[p] = s[0][p] == '0' ? '1' : '0';
  _(p + 1, c);
}
void york() {
  in >> n >> m;
  for (int i = 0; i < (m); ++i) in >> s[i] >> bingo[i];
  _(0, 0);
  cout << ans;
}
int main() {
  york();
  return 0;
}
