#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2 * 1e3 + 1;
int n, k, a[N];
int dp[1 << 12][N], prec[N];
int f(int mask, int pos) {
  if (pos == n) return 0;
  if (dp[mask][pos] != -1) return dp[mask][pos];
  int ret = 0;
  if (a[pos] == 0) {
    for (int i = 2; i <= 4; i += 2) {
      if (mask % i != 0) {
        ret = (ret + f(i, pos + 1)) % mod;
      } else {
        int m = mask + i;
        if ((m >> k) & 1)
          ret = (ret + prec[pos + 1]) % mod;
        else
          ret = (ret + f(m, pos + 1)) % mod;
      }
    }
  } else {
    if (mask % a[pos] != 0) {
      ret = (ret + f(a[pos], pos + 1)) % mod;
    } else {
      int m = mask + a[pos];
      if ((m >> k) & 1)
        ret = (ret + prec[pos + 1]) % mod;
      else
        ret = (ret + f(m, pos + 1)) % mod;
    }
  }
  return dp[mask][pos] = ret;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    prec[i] = 1;
  }
  prec[n] = 1;
  for (int i = n - 1; i >= 0; --i) {
    if (a[i] == 0)
      prec[i] = (prec[i + 1] * 2) % mod;
    else
      prec[i] = prec[i + 1];
  }
  memset(dp, -1, sizeof dp);
  int ans = f(0, 0);
  cout << ans << endl;
  return 0;
}
