#include <bits/stdc++.h>
using namespace std;
int n, k;
long long d[1024], d2[1024], ans = 0;
const int mod = 1e9 + 7;
long long twon[2005];
int sum0 = 0;
int a[2005];
int main() {
  cin >> n >> k;
  twon[0] = 1;
  for (int i = 1; i <= n; ++i) twon[i] = (twon[i - 1] << 1) % mod;
  k = (1 << (k - 1));
  for (int i = 0; i < (int)(k); i++) d[i] = 0;
  d[0] = 1;
  for (int q = 0; q < (int)(n); q++) {
    cin >> a[q];
    if (a[q] == 0) ++sum0;
  }
  for (int q = 0; q < (int)(n); q++) {
    int x = a[q];
    if (a[q] == 0) --sum0;
    x >>= 1;
    for (int i = 0; i < (int)(k); i++) d2[i] = 0;
    if (x == 0 || x == 1) {
      for (int i = 0; i < (int)(k - 1); i++) {
        d2[i + 1] = d[i];
      }
      ans = (ans + d[k - 1] * twon[sum0]) % mod;
    }
    if (x == 0 || x == 2) {
      for (int i = 0; i < (int)(k); i++) {
        int newi;
        if (i & 1)
          newi = 2;
        else
          newi = i + 2;
        if (newi < k)
          d2[newi] = (d2[newi] + d[i]) % mod;
        else
          ans = (ans + d[i] * twon[sum0]) % mod;
      }
    }
    for (int i = 0; i < (int)(k); i++) d[i] = d2[i];
  }
  cout << ans << endl;
  return 0;
}
