#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 10, K = 12, M = (1LL << K) + 10, mod = 1e9 + 7;
long long n, k, ans, ar[N], psum[N], pw2[N], dp[N][M];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  pw2[0] = 1;
  for (long long i = 1; i < N; i++) pw2[i] = (pw2[i - 1] * 2) % mod;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> ar[i];
  for (long long i = n - 1; i >= 0; i--)
    psum[i] = psum[i + 1] + (ar[i + 1] == 0 && i < n - 1);
  if (!ar[0])
    dp[0][2] = dp[0][4] = 1;
  else
    dp[0][ar[0]] = 1;
  for (long long i = 1; i < n; i++)
    for (long long msk = 2; msk <= (1LL << k); msk++) {
      if (msk & 1) continue;
      if (!ar[i]) {
        if (msk + 2 >= (1LL << k))
          ans = (ans + dp[i - 1][msk] * pw2[psum[i]]) % mod;
        else
          dp[i][msk + 2] = (dp[i][msk + 2] + dp[i - 1][msk]) % mod;
        if (msk % 4 == 0) {
          if (msk + 4 >= (1LL << k))
            ans = (ans + dp[i - 1][msk] * pw2[psum[i]]) % mod;
          else
            dp[i][msk + 4] = (dp[i][msk + 4] + dp[i - 1][msk]) % mod;
        } else
          dp[i][4] = (dp[i][4] + dp[i - 1][msk]) % mod;
      } else if (ar[i] == 2) {
        if (msk + 2 >= (1LL << k))
          ans = (ans + dp[i - 1][msk] * pw2[psum[i]]) % mod;
        else
          dp[i][msk + 2] = (dp[i][msk + 2] + dp[i - 1][msk]) % mod;
      } else if (ar[i] == 4 && msk % 4 == 0) {
        if (msk + 4 >= (1LL << k))
          ans = (ans + dp[i - 1][msk] * pw2[psum[i]]) % mod;
        else
          dp[i][msk + 4] = (dp[i][msk + 4] + dp[i - 1][msk]) % mod;
      } else if (ar[i] == 4)
        dp[i][4] = (dp[i][4] + dp[i - 1][msk]) % mod;
    }
  cout << ans;
}
