#include <bits/stdc++.h>
using namespace std;
long long rui(int n) {
  long long k = 1;
  for (int i = 0; i < n; i++) k = k * 2;
  return k;
}
int kyori(string s, string t) {
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != t[i]) ans = ans + 1;
  }
  return ans;
}
int main() {
  int m, n;
  cin >> n >> m;
  string a[10];
  long long ma = rui(n);
  int b[10];
  for (int i = 0; i < m; i++) {
    string s;
    int ss;
    cin >> s >> ss;
    a[i] = s;
    b[i] = ss;
  }
  int ans = 0;
  int c[330000][5];
  int j = 0;
  for (int i = 0; i < n; i++) {
    c[j][0] = i;
    if (b[0] > 1) {
      for (int ii = i + 1; ii < n; ii++) {
        c[j][0] = i;
        c[j][1] = ii;
        if (b[0] > 2) {
          for (int iii = ii + 1; iii < n; iii++) {
            c[j][0] = i;
            c[j][1] = ii;
            c[j][2] = iii;
            if (b[0] > 3) {
              for (int iiii = iii + 1; iiii < n; iiii++) {
                c[j][0] = i;
                c[j][1] = ii;
                c[j][2] = iii;
                c[j][3] = iiii;
                if (b[0] > 4) {
                  for (int iiiii = 1 + iiii; iiiii < n; iiiii++) {
                    c[j][0] = i;
                    c[j][1] = ii;
                    c[j][2] = iii;
                    c[j][3] = iiii;
                    c[j][4] = iiiii;
                    if (b[0] == 5) j = j + 1;
                  }
                }
                if (b[0] == 4) j = j + 1;
              }
            }
            if (b[0] == 3) j = j + 1;
          }
        }
        if (b[0] == 2) j = j + 1;
      }
    }
    if (b[0] == 1) j = j + 1;
  }
  int k = 0;
  string u = "";
  for (int i = 0; i < j; i++) {
    string u = a[0];
    for (int n = 0; n < b[0]; n++) {
      if (u[c[i][n]] == '0')
        u[c[i][n]] = '1';
      else
        u[c[i][n]] = '0';
    }
    k = 0;
    while (k < m) {
      if (kyori(u, a[k]) == b[k])
        k = k + 1;
      else
        break;
    }
    if (k == m) {
      ans = ans + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
