#include <bits/stdc++.h>
using namespace std;
int a[2010], s[2010];
int dp[2010][4010];
long long p2[2010];
const int mod = 1000000007;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i] >>= 1;
  }
  p2[0] = 1;
  for (int i = 0; i < n; i++) {
    p2[i + 1] = (p2[i] << 1);
    p2[i + 1] %= mod;
  }
  for (int i = n - 1; i >= 0; i--) {
    s[i] = s[i + 1] + (a[i] == 0);
  }
  k--;
  int ret = 0;
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (1 << k); j++) {
      if (!dp[i][j]) {
        continue;
      }
      if (a[i] == 1 || a[i] == 0) {
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] %= mod;
      }
      if (a[i] == 2 || a[i] == 0) {
        if (j & 1) {
          dp[i + 1][2] += dp[i][j];
          dp[i + 1][2] %= mod;
        } else {
          dp[i + 1][j + 2] += dp[i][j];
          dp[i + 1][j + 2] %= mod;
        }
      }
    }
    for (int j = (1 << k); j <= 4000; j++) {
      if (!dp[i + 1][j]) {
        continue;
      }
      ret += (p2[s[i + 1]]) % mod * dp[i + 1][j] % mod;
      ret %= mod;
    }
  }
  printf("%d\n", ret);
  return 0;
}
