#include <bits/stdc++.h>
using namespace std;
const long long MD = 1e9 + 7;
int n, k, a[2005], c[2005];
long long dp[2005][2049];
long long qpow(long long b, long long exp) {
  long long ret = 1;
  while (exp != 0) {
    if (exp % 2 == 1) {
      ret *= b;
      ret %= MD;
    }
    b *= b;
    b %= MD;
    exp /= 2;
  }
  return ret;
}
long long recurse(int cur, int sum) {
  if (sum >= (1 << k)) return qpow(2, c[cur]);
  if (cur == n) return 0;
  if (dp[cur][sum] != -1) return dp[cur][sum];
  dp[cur][sum] = 0;
  if (a[cur] != 4) dp[cur][sum] += recurse(cur + 1, sum + 2);
  if (a[cur] != 2) {
    if (sum & 2)
      dp[cur][sum] += recurse(cur + 1, 4);
    else
      dp[cur][sum] += recurse(cur + 1, sum + 4);
  }
  dp[cur][sum] %= MD;
  return dp[cur][sum];
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) c[i] = c[i + 1] + (a[i] == 0);
  memset(dp, -1, sizeof(dp));
  cout << recurse(0, 0) << '\n';
}
