#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int a[2005], p, i, j, dp[2005][4096], n, m, ans, sum[2005], P[2005];
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = n; i >= 1; i--)
    if (a[i] == 0) sum[i]++;
  for (i = n; i >= 1; i--) sum[i] += sum[i + 1];
  dp[0][0] = 1;
  p = (1 << 12);
  for (i = 1; i <= n; i++) {
    for (j = 0; j < (1 << m - 1); j++)
      if (dp[i - 1][j]) {
        if (j % 2 == 1) {
          if (a[i] != 4) dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % MOD;
          if (a[i] != 2) dp[i][2] = (dp[i][2] + dp[i - 1][j]) % MOD;
        } else {
          if (a[i] != 4) {
            dp[i][j + 1] = dp[i][j + 1] + dp[i - 1][j] % MOD;
          }
          if (a[i] != 2) {
            dp[i][j + 2] = dp[i][j + 2] + dp[i - 1][j] % MOD;
          }
        }
      }
  }
  P[0] = 1;
  for (j = 1; j <= 2000; j++) P[j] = P[j - 1] * 2 % MOD;
  for (j = 1; j <= n; j++)
    for (i = (1 << m - 1); i < p; i++)
      ans = (ans + (long long)dp[j][i] * P[sum[j + 1]] % MOD) % MOD;
  cout << ans;
  return 0;
}
