#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long MOD = 1e9 + 7;
const int MAX = 2e3 + 100;
int N, K;
vector<int> V;
long long DP[MAX][MAX];
long long solve(int pos, int mask) {
  if (pos == N) return (mask >= (1 << K));
  if (DP[pos][mask] + 1) return DP[pos][mask];
  long long ans = 0;
  if (V[pos] != 4) {
    if (mask >= (1 << K))
      ans = (ans + solve(pos + 1, mask)) % MOD;
    else
      ans = (ans + solve(pos + 1, (mask + 2))) % MOD;
  }
  if (V[pos] != 2) {
    if (mask >= (1 << K))
      ans = (ans + solve(pos + 1, mask)) % MOD;
    else if (mask & 2)
      ans = (ans + solve(pos + 1, 4)) % MOD;
    else
      ans = (ans + solve(pos + 1, mask + 4)) % MOD;
  }
  return DP[pos][mask] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  V.resize(N);
  for (auto& x : V) cin >> x;
  memset(DP, -1, sizeof DP);
  cout << solve(0, 0) << '\n';
  return 0;
}
