#include <bits/stdc++.h>
using namespace std;
vector<long long int> primes;
long long int MOD = 1e9 + 7;
void Sieve(long long int n) {
  vector<bool> prime(n + 1, true);
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) primes.push_back(p);
}
long long int dnc(long long int bas, long long int power, long long int mod) {
  if (power == 0) return 1;
  if (power % 2 == 0) {
    int res = dnc(bas, power / 2, mod);
    return 1LL * res * res % mod;
  }
  return 1LL * bas * dnc(bas, power - 1, mod) % mod;
}
long long int f[2 * 300010 + 1], inv[2 * 300010 + 1];
void precalc() {
  f[0] = inv[0] = 1;
  for (long long int temp = 1; temp <= 2 * 300010; temp++) {
    f[temp] = 1ll * temp * f[temp - 1] % MOD;
    inv[temp] = dnc(temp, MOD - 2, MOD) * inv[temp - 1] % MOD;
  }
}
long long int comb(long long int n, long long int k) {
  if (k > n || k < 0) return 0;
  return f[n] * inv[k] % MOD * inv[n - k] % MOD;
}
long long int n, k;
vector<vector<vector<long long int>>> dp;
void solve2(long long int i, long long int j) {
  long long int mask = j;
  if (!(mask & (1 << 0))) {
    mask += 2;
    if (mask >= pow(2, k)) {
      mask ^= (1 << k);
      dp[i][mask][1] += dp[i - 1][j][0] + dp[i - 1][j][1];
      dp[i][mask][1] %= MOD;
    } else {
      dp[i][mask][1] += dp[i - 1][j][1];
      dp[i][mask][0] += dp[i - 1][j][0];
      dp[i][mask][1] %= MOD;
      dp[i][mask][0] %= MOD;
    }
  }
}
void solve4(long long int i, long long int j) {
  long long int mask = j;
  if (!(mask & (1 << 0))) {
    if ((mask & (1 << 1))) {
      dp[i][4][0] += dp[i - 1][j][0];
      dp[i][4][1] += dp[i - 1][j][1];
      dp[i][4][0] %= MOD;
      dp[i][4][1] %= MOD;
    } else {
      mask += 4;
      if (mask >= pow(2, k)) {
        mask ^= (1 << k);
        dp[i][mask][1] += dp[i - 1][j][0] + dp[i - 1][j][1];
        dp[i][mask][1] %= MOD;
      } else {
        dp[i][mask][0] += dp[i - 1][j][0];
        dp[i][mask][1] += dp[i - 1][j][1];
        dp[i][mask][0] %= MOD;
        dp[i][mask][1] %= MOD;
      }
    }
  }
}
int main() {
  cin >> n;
  cin >> k;
  vector<long long int> a(n + 1);
  for (long long int i = 0; i < n; i++) cin >> a[i + 1];
  dp = vector<vector<vector<long long int>>>(
      n + 1,
      vector<vector<long long int>>(1 << k, vector<long long int>(2, 0)));
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (1 << k); j++) {
      if (a[i] == 2) solve2(i, j);
      if (a[i] == 4) solve4(i, j);
      if (a[i] == 0) {
        solve2(i, j);
        solve4(i, j);
      }
    }
  }
  long long int ans = 0;
  for (int j = 0; j < (1 << k); j++) {
    ans += dp[n][j][1];
    ans %= MOD;
  }
  cout << ans;
  return 0;
}
