#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
const long long MOD = 1000000007;
long long D[maxn][maxn];
long long n, k;
int main() {
  cin >> n >> k;
  D[0][0] = 1;
  --k;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    D[(1 << k)][i + 1] = D[(1 << k)][i];
    if (x == 0) {
      D[(1 << k)][i + 1] += D[(1 << k)][i];
      D[(1 << k)][i + 1] %= MOD;
    }
    for (int msk = 0; msk < (1 << k); ++msk) {
      int n_msk = msk;
      if (x == 4 || x == 0) {
        if ((msk & 1) == 1) {
          n_msk = 0;
          n_msk |= (1 << 1);
        } else {
          int u = 1;
          while (u <= k && ((n_msk & (1 << u)) != 0)) {
            n_msk ^= (1 << u);
            ++u;
          }
          n_msk ^= (1 << u);
        }
        D[n_msk][i + 1] += D[msk][i];
        D[n_msk][i + 1] %= MOD;
      }
      if (x == 2 || x == 0) {
        int n_msk = msk;
        int u = 0;
        while (u <= k && ((n_msk & (1 << u)) != 0)) {
          n_msk ^= (1 << u);
          ++u;
        }
        n_msk ^= (1 << u);
        D[n_msk][i + 1] += D[msk][i];
        D[n_msk][i + 1] %= MOD;
      }
    }
  }
  cout << D[(1 << k)][n] % MOD << endl;
}
