#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n, k, x;
int dp[2050];
int main() {
  scanf("%d%d", &n, &k);
  int maxn = (1 << k);
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x == 2) {
      dp[maxn] = (dp[maxn] + dp[maxn - 2]) % mod;
      for (int j = maxn - 2; j >= 2; j -= 2) {
        dp[j] = dp[j - 2];
      }
      dp[0] = 0;
    } else if (x == 4) {
      int ret = 0;
      dp[maxn] = (dp[maxn] + dp[maxn - 4]) % mod;
      for (int j = maxn - 2; j >= 2; j -= 2) {
        if ((j & 3) == 0)
          dp[j] = dp[j - 4];
        else {
          ret = (ret + dp[j]) % mod;
          dp[j] = 0;
        }
      }
      dp[4] = (dp[4] + ret) % mod;
      dp[0] = 0;
    } else if (x == 0) {
      int ret = 0;
      dp[maxn] =
          (((dp[maxn - 2] + dp[maxn - 4]) % mod) + ((2 * dp[maxn]) % mod)) %
          mod;
      for (int j = maxn - 2; j >= 2; j -= 2) {
        if ((j & 3) != 0) {
          ret = (ret + dp[j]) % mod;
        }
        dp[j] = dp[j - 2];
        if ((j & 3) == 0) dp[j] = (dp[j] + dp[j - 4]) % mod;
      }
      dp[4] = (dp[4] + ret) % mod;
      dp[0] = 0;
    }
  }
  printf("%d\n", dp[maxn]);
  return 0;
}
