#include <bits/stdc++.h>
using namespace std;
int arr[11];
string str[11];
int m, n;
int f(int k) {
  if (k == n) {
    for (int i = 0; i < m; i++)
      if (arr[i] != 0) return 0;
    return 1;
  }
  int ans = 0;
  bool c = 0;
  for (int i = 0; i < m; i++)
    if (str[i][k] == '0') {
      arr[i]--;
      if (arr[i] < 0) c++;
    }
  if (c == 0) ans += f(k + 1);
  for (int i = 0; i < m; i++)
    if (str[i][k] == '0') arr[i]++;
  c = 0;
  for (int i = 0; i < m; i++)
    if (str[i][k] == '1') {
      arr[i]--;
      if (arr[i] < 0) c++;
    }
  if (!c) ans += f(k + 1);
  for (int i = 0; i < m; i++)
    if (str[i][k] == '1') arr[i]++;
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> str[i] >> arr[i];
  cout << f(0) << endl;
  return 0;
}
