#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[2005];
int f[2005][1 << 11];
int md = 1000000007;
int cnt[2005];
int pw[2005];
int x[25], sz;
int res;
void add(int &x, int y) {
  x += y;
  if (x >= md) x -= md;
}
void push(int id, int mask, int a) {
  sz = 0;
  for (int(i) = 0; (i) < (k); ++(i))
    if ((mask >> i) & 1) x[sz++] = i;
  if (!sz) {
    add(f[id][1 << a], f[id - 1][mask]);
    return;
  }
  if (a < x[0]) {
    add(f[id][mask | (1 << a)], f[id - 1][mask]);
    return;
  }
  if (a > x[0]) {
    add(f[id][1 << a], f[id - 1][mask]);
    return;
  }
  ++x[0];
  int start = 0;
  for (int(j) = 0; (j) < (sz - 1); ++(j))
    if (x[j] == x[j + 1]) {
      ++x[j + 1];
      start = j + 1;
    } else
      break;
  int nmask = 0;
  for (int i = start; i < sz; ++i) nmask |= 1 << x[i];
  if (x[sz - 1] >= k - 1) {
    add(res, 1LL * f[id - 1][mask] * pw[cnt[id + 1]] % md);
    return;
  }
  add(f[id][nmask], f[id - 1][mask]);
}
int main(void) {
  cin.sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  pw[0] = 1;
  for (int i = 1; i < 2005; ++i) pw[i] = (pw[i - 1] + pw[i - 1]) % md;
  for (int(i) = 0; (i) < (n); ++(i)) cin >> a[i + 1];
  for (int i = n; i >= 0; --i) {
    cnt[i] = cnt[i + 1] + (a[i] == 0);
    if (a[i] == 0) a[i] = -1;
    if (a[i] == 2) a[i] = 0;
    if (a[i] == 4) a[i] = 1;
  }
  f[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int(j) = 0; (j) < (1 << k); ++(j))
      if (f[i - 1][j]) {
        if (a[i] == -1)
          push(i, j, 0), push(i, j, 1);
        else
          push(i, j, a[i]);
      }
  }
  cout << res << "\n";
  return 0;
}
