#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 7;
const int P = 1e9 + 7;
int n, K, a[N], dp[2][1 << 11], pd[2][1 << 11];
inline void inc(int &x, int y) {
  if ((x += y) >= P) x -= P;
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = (1); i < (n + 1); ++i) scanf("%d", a + i);
  dp[0][0] = 1;
  for (int i = (1); i < (n + 1); ++i) {
    for (int j = (0); j < (2); ++j)
      for (int mask = (0); mask < (1 << K); ++mask)
        pd[j][mask] = dp[j][mask], dp[j][mask] = 0;
    for (int w = (1); w < (3); ++w) {
      int x = 1 << w;
      if (a[i] == 6 - x) continue;
      for (int j = (0); j < (2); ++j)
        for (int mask = (0); mask < (1 << K); ++mask) {
          if (!pd[j][mask]) continue;
          int nj = j, nmask = x <= ((mask) & (-mask)) ? mask + x : x;
          if (nmask >= (1 << K)) nj = 1, nmask = 0;
          inc(dp[nj][nmask], pd[j][mask]);
        }
    }
  }
  int ans = 0;
  for (int mask = (0); mask < (1 << K); ++mask) inc(ans, dp[1][mask]);
  printf("%d\n", ans);
  return 0;
}
