#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read() {
  T x;
  cin >> x;
  return x;
}
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {-1, 1, 0, 0, 1, -1, -1, 1};
void run();
int main() {
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(16);
  run();
}
int a[2222], n, k, f[2048][2048][2][2];
const int mod = 1e9 + 7;
void add(int& x, int y) { x = (x + y) % mod; }
int solve(int i, int j, int rem, bool finished) {
  if (i == n) return finished;
  int& res = f[i][j][rem][finished];
  if (res != -1) return res;
  if (finished) {
    if (a[i] == 0)
      return 2LL * solve(i + 1, j, rem, finished) % mod;
    else
      return solve(i + 1, j, rem, finished);
  }
  int lo = a[i] ? a[i] : 2;
  int hi = a[i] ? a[i] : 4;
  res = 0;
  for (int x = lo; x <= hi; x += 2) {
    if (rem == 1 && x == 2)
      add(res, solve(i + 1, j + 1, 0, (j + 1) >= (1 << (k - 2))));
    else if (rem == 0 && x == 2)
      add(res, solve(i + 1, j, 1, 0));
    else if (rem == 0 && x == 4)
      add(res, solve(i + 1, j + 1, 0, (j + 1) >= (1 << (k - 2))));
    else if (rem == 1 && x == 4)
      add(res, solve(i + 1, 1, 0, 0));
  }
  return res;
}
void run() {
  cin >> n >> k;
  for (int i = (0), __ee = (n); i < __ee; ++i) cin >> a[i];
  memset(f, -1, sizeof f);
  cout << solve(0, 0, 0, 0) << "\n";
}
