#include <bits/stdc++.h>
inline int getint() {
  register char ch;
  while (!isdigit(ch = getchar()))
    ;
  register int x = ch ^ '0';
  while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ '0');
  return x;
}
const int K = 10, mod = 1e9 + 7;
int f[2][(1 << K) + 1];
int main() {
  const int n = getint(), k = getint() - 1;
  for (register int i = f[0][0] = 1; i <= n; i++) {
    const int x = getint();
    std::fill(&f[i & 1][0], &f[i & 1][1 << k] + 1, 0);
    if (x != 2) {
      for (register int j = 0; j <= 1 << k; j++) {
        (f[i & 1][j & 1 ? 2 : std::min(j + 2, 1 << k)] += f[(i & 1) ^ 1][j]) %=
            mod;
      }
    }
    if (x != 4) {
      for (register int j = 0; j <= 1 << k; j++) {
        (f[i & 1][std::min(j + 1, 1 << k)] += f[(i & 1) ^ 1][j]) %= mod;
      }
    }
  }
  printf("%d\n", f[n & 1][1 << k]);
  return 0;
}
