#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, k;
long long dp[2050][4100][2];
int a[2050];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (1 << 12); j++) {
      if (a[i] == 2) {
        int to = j + 1;
        if (to < (1 << (k - 1))) {
          dp[i][to][0] = (dp[i][to][0] + dp[i - 1][j][0]) % mod;
          dp[i][to][1] = (dp[i][to][1] + dp[i - 1][j][1]) % mod;
        } else {
          dp[i][to][1] =
              (dp[i][to][1] + dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
        }
      } else if (a[i] == 4) {
        int to;
        if (j & 1) {
          to = 2;
          dp[i][to][0] = (dp[i][to][0] + dp[i - 1][j][0]) % mod;
          dp[i][to][1] = (dp[i][to][1] + dp[i - 1][j][1]) % mod;
        } else {
          to = j + 2;
          if (to < (1 << (k - 1))) {
            dp[i][to][0] = (dp[i][to][0] + dp[i - 1][j][0]) % mod;
            dp[i][to][1] = (dp[i][to][1] + dp[i - 1][j][1]) % mod;
          } else {
            dp[i][to][1] =
                (dp[i][to][1] + dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
          }
        }
      } else {
        int to = j + 1;
        if (to < (1 << (k - 1))) {
          dp[i][to][0] = (dp[i][to][0] + dp[i - 1][j][0]) % mod;
          dp[i][to][1] = (dp[i][to][1] + dp[i - 1][j][1]) % mod;
        } else {
          dp[i][to][1] =
              (dp[i][to][1] + dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
        }
        if (j & 1) {
          to = 2;
          dp[i][to][0] = (dp[i][to][0] + dp[i - 1][j][0]) % mod;
          dp[i][to][1] = (dp[i][to][1] + dp[i - 1][j][1]) % mod;
        } else {
          to = j + 2;
          if (to < (1 << (k - 1))) {
            dp[i][to][0] = (dp[i][to][0] + dp[i - 1][j][0]) % mod;
            dp[i][to][1] = (dp[i][to][1] + dp[i - 1][j][1]) % mod;
          } else {
            dp[i][to][1] =
                (dp[i][to][1] + dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j < (1 << 12); j++) ans = (ans + dp[n][j][1]) % mod;
  printf("%lld\n", ans);
}
