#include <bits/stdc++.h>
using namespace std;
int k, dp[2][(1 << 10) + 1];
int get_mask(int mask, int x) {
  int mask2 = mask;
  if (x == 1 && (mask & 1) != 0) return 2;
  mask += (1 << x);
  if ((mask & (1 << (k - 1))) != 0) return (1 << (k - 1));
  return mask;
}
int main() {
  int n;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 0, r = 0; i < n; ++i, r ^= 1) {
    memset(dp[r ^ 1], 0, sizeof dp[r ^ 1]);
    for (int mask = 0; mask <= (1 << (k - 1)); ++mask) {
      if (a[i] == 0 || a[i] == 2) {
        int mask2 = get_mask(mask, 0);
        dp[r ^ 1][mask2] += dp[r][mask];
        if (dp[r ^ 1][mask2] >= 1000000007) dp[r ^ 1][mask2] -= 1000000007;
      }
      if (a[i] == 0 || a[i] == 4) {
        int mask2 = get_mask(mask, 1);
        dp[r ^ 1][mask2] += dp[r][mask];
        if (dp[r ^ 1][mask2] >= 1000000007) dp[r ^ 1][mask2] -= 1000000007;
      }
    }
  }
  cout << dp[n & 1][(1 << (k - 1))] << endl;
  return 0;
}
