#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e12 + 21;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
void precision(long long pr) {
  cout.precision(pr);
  cout << fixed;
}
const int N = 1e6 + 21;
long long dp[2021][2221][2], a[2021], n, k;
long long f(long long i, long long num, long long sw) {
  if (num >= (1 << k)) sw = 1;
  if (sw == 1) num = 0;
  if (i >= n) {
    if (sw) return 1;
    return 0;
  }
  long long &ret = dp[i][num][sw], x, t = 0;
  if (ret != -1) return ret % mod;
  ret = 0;
  long long y = (num & (-num));
  if (a[i] == 0) {
    ret = (f(i + 1, num + 2, sw) % mod);
    ret = ret % mod;
    if (4 <= y)
      ret = ((ret % mod) + (f(i + 1, num + 4, sw) % mod)) % mod;
    else
      ret = ((ret % mod) + f(i + 1, 4, sw) % mod) % mod;
    ret = ret % mod;
    return ret % mod;
  }
  if (a[i] == 2)
    ret = f(i + 1, num + 2, sw) % mod;
  else if (4 <= y)
    ret = f(i + 1, num + 4, sw) % mod;
  else
    ret = f(i + 1, 4, sw) % mod;
  ret = ret % mod;
  return ret % mod;
}
int main() {
  long long i, j;
  memset(dp, (-1), sizeof(dp));
  cin >> n >> k;
  for ((i) = (int)(0); (i) <= (int)(n - 1); (i)++) cin >> a[i];
  long long ans = f(0, 0, 0) % mod;
  ans = ans % mod;
  cout << ans << '\n';
  return 0;
}
