#include <bits/stdc++.h>
#pragma GCC optimization("O3")
using namespace std;
template <typename T>
inline void Cin(T& first) {
  char c;
  T sign = 1;
  first = 0;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) first = first * 10 + c - '0';
  first *= sign;
}
template <typename T>
inline void Out(T first) {
  if (first > 9) Out(first / 10);
  putchar(first % 10 + '0');
}
template <typename T>
inline void Cout(T first, char c) {
  if (first < 0) putchar('-');
  first = abs(first);
  Out(first);
  putchar(c);
}
template <typename T, typename... Args>
inline void Cin(T& a, Args&... args) {
  Cin(a);
  Cin(args...);
}
template <typename T, typename... Args>
inline void Cout(T a, char c, Args... args) {
  Cout(a, c);
  Cout(args...);
}
const int mod = int(1e9) + 7;
const int N = 2050;
int f[N][N], a[N], n, k, nState;
void Enter() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
}
void add(int& first, int second) {
  if ((first += second) >= mod) first -= mod;
}
void Solve() {
  nState = 1 << k, f[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int bit = 0; bit <= nState; ++bit) {
      if (!f[i - 1][bit]) continue;
      if (a[i] == 2 || a[i] == 0) {
        if (bit + 2 >= nState)
          add(f[i][nState], f[i - 1][bit]);
        else
          add(f[i][bit + 2], f[i - 1][bit]);
      }
      if (a[i] == 4 || a[i] == 0) {
        if ((bit >> 1) & 1)
          add(f[i][4], f[i - 1][bit]);
        else {
          if (bit + 4 >= nState)
            add(f[i][nState], f[i - 1][bit]);
          else
            add(f[i][bit + 4], f[i - 1][bit]);
        }
      }
    }
  }
  cout << f[n][nState];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("test"
            ".inp",
            "r")) {
    freopen(
        "test"
        ".inp",
        "r", stdin);
    freopen(
        "test"
        ".out",
        "w", stdout);
  }
  Enter(), Solve();
  return 0;
}
