#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10, Maxn = 4e6 + 10, lg = 22;
const int mod = 1e9 + 7;
const long long inf = 1e18 + 10;
long long dp[maxn][maxn];
int a[maxn];
int n;
int psum[maxn], k;
int p[maxn];
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  p[0] = 1;
  for (int i = 1; i < maxn; i++) p[i] = ((p[i - 1] * 2) % mod);
  for (int i = n - 1; i >= 0; i--) {
    psum[i] = psum[i + 1];
    if (a[i] == 0) psum[i]++;
  }
  if (a[0] != 2) dp[0][4] = 1;
  if (a[0] != 4) dp[0][2] = 1;
  long long ans = 0;
  k = p[k];
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < maxn; j++) {
      if (dp[i][j] == 0) continue;
      if (a[i + 1] != 2) {
        if (j % 4 == 2) {
          dp[i + 1][4] = (dp[i][j] + dp[i + 1][4]) % mod;
        } else {
          if (j + 4 >= k) {
            ans = (ans + (dp[i][j] * p[psum[i + 2]])) % mod;
          } else
            dp[i + 1][j + 4] = (dp[i + 1][j + 4] + dp[i][j]) % mod;
        }
      }
      if (a[i + 1] != 4) {
        if (j + 2 >= k) {
          ans = (ans + (dp[i][j] * p[psum[i + 2]])) % mod;
        } else {
          dp[i + 1][j + 2] = (dp[i + 1][j + 2] + dp[i][j]) % mod;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
