#include <bits/stdc++.h>
using namespace std;
const int maxN = 10 + 5;
int a[maxN];
string s[maxN];
int n, m;
int check(string str) {
  for (int i = 0; i < m; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (str[j] == s[i][j]) {
        cnt++;
      }
    }
    if (cnt != a[i]) {
      return false;
    }
  }
  return true;
}
inline int change(char c) {
  if (c == '0') return '1';
  return '0';
}
int sol0() {
  int ans = 0;
  string sa = s[0];
  for (int i = 0; i < n; i++) {
    sa[i] = change(sa[i]);
  }
  if (check(sa)) {
    return 1;
  }
  return 0;
}
int sol1() {
  int ans = 0;
  string sa = s[0];
  for (int i = 0; i < n; i++) {
    sa[i] = change(sa[i]);
  }
  for (int c1 = 0; c1 < n; c1++) {
    string tmp = sa;
    tmp[c1] = change(tmp[c1]);
    if (check(tmp)) {
      ans++;
    }
  }
  return ans;
}
int sol2() {
  int ans = 0;
  string sa = s[0];
  for (int i = 0; i < n; i++) {
    sa[i] = change(sa[i]);
  }
  for (int c1 = 0; c1 < n; c1++) {
    for (int c2 = c1 + 1; c2 < n; c2++) {
      string tmp = sa;
      tmp[c1] = change(tmp[c1]);
      tmp[c2] = change(tmp[c2]);
      if (check(tmp)) {
        ans++;
      }
    }
  }
  return ans;
}
int sol3() {
  int ans = 0;
  string sa = s[0];
  for (int i = 0; i < n; i++) {
    sa[i] = change(sa[i]);
  }
  for (int c1 = 0; c1 < n; c1++) {
    for (int c2 = c1 + 1; c2 < n; c2++) {
      for (int c3 = c2 + 1; c3 < n; c3++) {
        string tmp = sa;
        tmp[c1] = change(tmp[c1]);
        tmp[c2] = change(tmp[c2]);
        tmp[c3] = change(tmp[c3]);
        if (check(tmp)) {
          ans++;
        }
      }
    }
  }
  return ans;
}
int sol4() {
  int ans = 0;
  string sa = s[0];
  for (int i = 0; i < n; i++) {
    sa[i] = change(sa[i]);
  }
  for (int c1 = 0; c1 < n; c1++) {
    for (int c2 = c1 + 1; c2 < n; c2++) {
      for (int c3 = c2 + 1; c3 < n; c3++) {
        for (int c4 = c3 + 1; c4 < n; c4++) {
          string tmp = sa;
          tmp[c1] = change(tmp[c1]);
          tmp[c2] = change(tmp[c2]);
          tmp[c3] = change(tmp[c3]);
          tmp[c4] = change(tmp[c4]);
          if (check(tmp)) {
            ans++;
          }
        }
      }
    }
  }
  return ans;
}
int sol5() {
  int ans = 0;
  string sa = s[0];
  for (int i = 0; i < n; i++) {
    sa[i] = change(sa[i]);
  }
  for (int c1 = 0; c1 < n; c1++) {
    for (int c2 = c1 + 1; c2 < n; c2++) {
      for (int c3 = c2 + 1; c3 < n; c3++) {
        for (int c4 = c3 + 1; c4 < n; c4++) {
          for (int c5 = c4 + 1; c5 < n; c5++) {
            string tmp = sa;
            tmp[c1] = change(tmp[c1]);
            tmp[c2] = change(tmp[c2]);
            tmp[c3] = change(tmp[c3]);
            tmp[c4] = change(tmp[c4]);
            tmp[c5] = change(tmp[c5]);
            if (check(tmp)) {
              ans++;
            }
          }
        }
      }
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> a[i];
  }
  if (a[0] == 0)
    printf("%d\n", sol0());
  else if (a[0] == 1)
    printf("%d\n", sol1());
  else if (a[0] == 2)
    printf("%d\n", sol2());
  else if (a[0] == 3)
    printf("%d\n", sol3());
  else if (a[0] == 4)
    printf("%d\n", sol4());
  else if (a[0] == 5)
    printf("%d\n", sol5());
}
