#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  int res;
  int n, m;
  vector<string> vs;
  vector<int> expected_diff;
  void backtracking(string& s, vector<int>& diff) {
    if (s.size() == n) {
      for (int i = 0; i < m; i++) {
        if (diff[i] != expected_diff[i]) return;
      }
      res++;
      return;
    }
    for (int i = 0; i < m; i++) {
      if (diff[i] > expected_diff[i] ||
          diff[i] + n - s.size() < expected_diff[i])
        return;
    }
    int idx = s.size();
    for (char c = '0'; c <= '1'; c++) {
      for (int i = 0; i < m; i++)
        if (c != vs[i][idx]) diff[i]++;
      s.push_back(c);
      backtracking(s, diff);
      for (int i = 0; i < m; i++)
        if (c != vs[i][idx]) diff[i]--;
      s.pop_back();
    }
  }
  Solution(int n, int m) {
    this->n = n;
    this->m = m;
    vs.assign(m, string());
    expected_diff.assign(m, 0);
  }
  int calculate() {
    res = 0;
    string s;
    vector<int> diff(m, 0);
    backtracking(s, diff);
    return res;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  Solution obj(n, m);
  for (int i = 0; i < m; i++) cin >> obj.vs[i] >> obj.expected_diff[i];
  cout << obj.calculate() << '\n';
  return 0;
}
