#include <bits/stdc++.h>
using namespace std;
const int size = 400007;
const long long modulo = 1000000007;
const int INF = 2e9;
const double EPS = 1e-8;
const double PI = acos(-1.0);
long long dp[2007][1027];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  --k;
  vector<int> a(n);
  long long total = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] /= 2;
    if (a[i] == 0) total = (total * 2) % modulo;
  }
  dp[0][0] = 1;
  int limit = (1 << k);
  for (int pos = 1; pos <= n; pos++)
    for (int sum = 0; sum < limit; sum++) {
      if (a[pos - 1] < 2)
        dp[pos][sum + 1] = (dp[pos][sum + 1] + dp[pos - 1][sum]) % modulo;
      if (a[pos - 1] != 1) {
        if (sum & 1)
          dp[pos][2] = (dp[pos][2] + dp[pos - 1][sum]) % modulo;
        else if (sum + 2 < limit)
          dp[pos][sum + 2] = (dp[pos][sum + 2] + dp[pos - 1][sum]) % modulo;
      }
    }
  long long ans = 0;
  for (int i = 0; i < limit; i++) ans += dp[n][i];
  ans %= modulo;
  ans = (total + modulo - ans) % modulo;
  cout << ans << endl;
  return 0;
}
