#include <bits/stdc++.h>
const int MAXN = 2100;
const int MOD = 1e9 + 7;
const int MAXK = 13;
int n, k, ans, b[MAXN], dp[MAXN][1 << MAXK][2];
using namespace std;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> b[i];
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int mask = 0; mask < (1 << MAXK); mask += 2) {
      int m1, m2;
      int t1 = 0;
      int t2 = 0;
      if (2 > (mask & -mask))
        m1 = 2;
      else
        m1 = mask + 2;
      if (4 > (mask & -mask))
        m2 = 4;
      else
        m2 = mask + 4;
      if (m1 >= (1 << k)) t1 = 1;
      if (m2 >= (1 << k)) t2 = 1;
      if (b[i + 1] == 2) {
        dp[i + 1][m1][t1] = (dp[i + 1][m1][t1] + dp[i][mask][0]) % MOD;
        dp[i + 1][m1][1] = (dp[i + 1][m1][1] + dp[i][mask][1]) % MOD;
      } else if (b[i + 1] == 4) {
        dp[i + 1][m2][t2] = (dp[i + 1][m2][t2] + dp[i][mask][0]) % MOD;
        dp[i + 1][m2][1] = (dp[i + 1][m2][1] + dp[i][mask][1]) % MOD;
      } else {
        dp[i + 1][m1][t1] = (dp[i + 1][m1][t1] + dp[i][mask][0]) % MOD;
        dp[i + 1][m1][1] = (dp[i + 1][m1][1] + dp[i][mask][1]) % MOD;
        dp[i + 1][m2][t2] = (dp[i + 1][m2][t2] + dp[i][mask][0]) % MOD;
        dp[i + 1][m2][1] = (dp[i + 1][m2][1] + dp[i][mask][1]) % MOD;
      }
    }
  }
  for (int i = 0; i < (1 << MAXK); i += 2) ans = (ans + dp[n][i][1]) % MOD;
  cout << ans;
}
