#include <bits/stdc++.h>
using namespace std;
int table[10][35];
int N, M;
int search(int ind, vector<pair<int, int> > v);
int main() {
  scanf("%d %d ", &N, &M);
  vector<pair<int, int> > v(M);
  for (int i = 0; i < M; i++) {
    int b;
    for (int j = 0; j < N; j++) {
      char c;
      scanf("%c ", &c);
      table[i][j] = c - '0';
    }
    scanf(" %d ", &v[i].first);
  }
  for (int i = 0; i < M; i++) {
    v[i].second = N - v[i].first;
  }
  cout << search(0, v) << endl;
}
int search(int ind, vector<pair<int, int> > v) {
  if (ind == N) {
    return 1;
  }
  int sum = 0;
  for (int i = 0; i <= 1; i++) {
    vector<pair<int, int> > _v = v;
    for (int j = 0; j < M; j++) {
      if (table[j][ind] == i) {
        if (_v[j].first >= 1) {
          _v[j].first--;
        } else {
          goto next;
        }
      } else {
        if (_v[j].second >= 1) {
          _v[j].second--;
        } else {
          goto next;
        }
      }
    }
    sum += search(ind + 1, _v);
  next:;
  }
  return sum;
}
