#include <bits/stdc++.h>
using namespace std;
const int nmax = 2005;
const int smax = (1 << 11) + 4;
long long r = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  int a[nmax];
  int sum = 1 << k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long pr[nmax] = {};
  pr[n] = 1;
  for (int i = n - 1; i >= 0; --i)
    if (a[i] == 0)
      pr[i] = (2 * pr[i + 1]) % r;
    else
      pr[i] = pr[i + 1];
  long long dp[2][smax][2] = {};
  dp[0][0][0] = 1;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int s = 0; s < sum; ++s) {
      if (a[i] == 0 || a[i] == 2) {
        dp[1][s + 2][1] += dp[0][s][0];
        dp[1][s + 2][0] += dp[0][s][1];
      }
      if (a[i] == 0 || a[i] == 4) {
        dp[1][s + 4][0] += dp[0][s][0];
        dp[1][4][0] += dp[0][s][1];
      }
    }
    for (int s = 0; s < sum + 4; ++s)
      for (int p = 0; p < 2; ++p) {
        dp[0][s][p] = dp[1][s][p] % r;
        dp[1][s][p] = 0;
      }
    for (int s = sum; s < sum + 4; ++s)
      for (int p = 0; p < 2; ++p) {
        ans = (ans + dp[0][s][p] * pr[i + 1]) % r;
        dp[0][s][p] = 0;
      }
  }
  cout << ans << '\n';
  return 0;
}
