#include <bits/stdc++.h>
using namespace std;
string src[15];
int mist[15];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> src[i] >> mist[i];
  }
  long long answer = 0;
  int got[15][40];
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      got[i][j] = src[i][j] - '0';
    }
  }
  int offer[40];
  if (mist[0] == 0) {
    for (int i = 0; i < n; ++i) offer[i] = got[0][i] ^ 1;
    for (int i = 1; i < m; ++i) {
      int cnt = 0;
      for (int j = 0; j < n; ++j) {
        if (offer[j] == got[i][j]) ++cnt;
      }
      if (mist[i] != cnt) {
        cout << 0;
        return 0;
      }
    }
    cout << 1;
    return 0;
  }
  int i[5];
  for (i[0] = 0; i[0] < n; ++i[0]) {
    for (i[1] = i[0] + (mist[0] > 1 ? 1 : 0);
         i[1] < (mist[0] > 1 ? n : i[0] + 1); ++i[1]) {
      for (i[2] = i[1] + (mist[0] > 2 ? 1 : 0);
           i[2] < (mist[0] > 2 ? n : i[1] + 1); ++i[2]) {
        for (i[3] = i[2] + (mist[0] > 3 ? 1 : 0);
             i[3] < (mist[0] > 3 ? n : i[2] + 1); ++i[3]) {
          for (i[4] = i[3] + (mist[0] > 4 ? 1 : 0);
               i[4] < (mist[0] > 4 ? n : i[3] + 1); ++i[4]) {
            for (int a = 0; a < n; ++a) offer[a] = got[0][a] ^ 1;
            for (int a = 0; a < 5; ++a) offer[i[a]] = got[0][i[a]];
            bool flag = true;
            for (int a = 1; a < m; ++a) {
              int cnt = 0;
              for (int b = 0; b < n; ++b)
                if (offer[b] == got[a][b]) ++cnt;
              if (cnt != mist[a]) {
                flag = false;
                break;
              }
            }
            if (flag) ++answer;
          }
        }
      }
    }
  }
  cout << answer;
  return 0;
}
