#include <bits/stdc++.h>
using namespace std;
const int N = 2005, md = 1000000000 + 7, maxst = 1 << 12;
vector<int> A;
int suf[N], ans, hi1[N], bits, j, n, k, i, a[N], dp[N][maxst];
void pl(int &x, int y) {
  x += y;
  if (x >= md) x -= md;
}
void push(int id, int mask, int add) {
  int i, f = 15;
  for (i = 0; i < k; i++)
    if (mask & (1 << i)) {
      f = i;
      break;
    }
  if (add < f) {
    pl(dp[id][mask + hi1[add]], dp[id - 1][mask]);
    return;
  }
  if (add > f) {
    pl(dp[id][hi1[add]], dp[id - 1][mask]);
    return;
  }
  int nmask = 0, x = mask;
  A.clear();
  while (x > 0) {
    A.push_back(x % 2);
    x /= 2;
  }
  A.push_back(0);
  A[add] = 2;
  while (A[add] == 2) {
    A[add++] = 0;
    A[add]++;
  }
  for (i = 0; i < A.size(); i++)
    if (A[i]) nmask += hi1[i];
  if (nmask >= hi1[k]) {
    pl(ans, (1ll * dp[id - 1][mask] * hi1[suf[id + 1]]) % md);
    return;
  }
  pl(dp[id][nmask], dp[id - 1][mask]);
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  bits = 1 << k;
  hi1[0] = 1;
  for (i = 1; i < N; i++) hi1[i] = (hi1[i - 1] + hi1[i - 1]) % md;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = a[i] / 2;
  }
  for (i = n; i > 0; i--) suf[i] += suf[i + 1] + (!a[i]);
  dp[0][0] = 1;
  for (i = 1; i <= n; i++)
    for (j = 0; j < bits; j++)
      if (dp[i - 1][j]) {
        if (a[i] == 0) {
          push(i, j, 1);
          push(i, j, 2);
        } else
          push(i, j, a[i]);
      }
  printf("%d", ans);
}
