#include <bits/stdc++.h>
using namespace std;
long long tonum(const string& s) {
  long long fac = 1;
  long long res = 0;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == '1') res += fac;
    fac <<= 1;
  }
  return res;
}
set<long long> generate(const string& s, int v) {
  long long num = tonum(s);
  set<long long> res;
  int len = s.length();
  if (v == 0) {
    long long nn = ~num;
    res.insert(nn & ((1ll << 35) - 1));
  } else if (v == 1) {
    for (int a = 0; a < s.length(); a++) {
      long long nn = ~num;
      nn ^= (1ll << a);
      res.insert(nn & ((1ll << 35) - 1));
    }
  } else if (v == 2) {
    for (int a = 0; a < s.length(); a++) {
      for (int b = a + 1; b < s.length(); b++) {
        long long nn = ~num;
        nn ^= (1ll << a);
        nn ^= (1ll << b);
        res.insert(nn & ((1ll << 35) - 1));
      }
    }
  } else if (v == 3) {
    for (int a = 0; a < s.length(); a++) {
      for (int b = a + 1; b < s.length(); b++) {
        for (int c = b + 1; c < s.length(); c++) {
          long long nn = ~num;
          nn ^= (1ll << a);
          nn ^= (1ll << b);
          nn ^= (1ll << c);
          res.insert(nn & ((1ll << 35) - 1));
        }
      }
    }
  } else if (v == 4) {
    for (int a = 0; a < s.length(); a++) {
      for (int b = a + 1; b < s.length(); b++) {
        for (int c = b + 1; c < s.length(); c++) {
          for (int d = c + 1; d < s.length(); d++) {
            long long nn = ~num;
            nn ^= (1ll << a);
            nn ^= (1ll << b);
            nn ^= (1ll << c);
            nn ^= (1ll << d);
            res.insert(nn & ((1ll << 35) - 1));
          }
        }
      }
    }
  } else if (v == 5) {
    for (int a = 0; a < s.length(); a++) {
      for (int b = a + 1; b < s.length(); b++) {
        for (int c = b + 1; c < s.length(); c++) {
          for (int d = c + 1; d < s.length(); d++) {
            for (int e = d + 1; e < s.length(); e++) {
              long long nn = ~num;
              nn ^= (1ll << a);
              nn ^= (1ll << b);
              nn ^= (1ll << c);
              nn ^= (1ll << d);
              nn ^= (1ll << e);
              res.insert(nn & ((1ll << 35) - 1));
            }
          }
        }
      }
    }
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  int v;
  cin >> s >> v;
  set<long long> hope = generate(s, v);
  for (int i = 1; i < m; i++) {
    cin >> s >> v;
    set<long long> new_hope = generate(s, v);
    set<long long> added;
    for (auto it = hope.begin(); it != hope.end(); it++) {
      if (new_hope.count(*it) > 0) {
        added.insert(*it);
      }
    }
    hope = added;
  }
  cout << hope.size() << endl;
  return 0;
}
