#include <bits/stdc++.h>
using namespace std;
const int maxn = 2049;
long long dp[maxn][maxn][2];
int a[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  k = pow(2, k);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) cin >> a[i];
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < maxn; j++) {
      int p;
      if (a[i] == 0 || a[i] == 2) {
        p = min(j + 2, 2048);
        dp[i][p][0] = (dp[i][p][0] + dp[i - 1][j][0]) % 1000000007;
        ;
        dp[i][p][1] = (dp[i][p][1] + dp[i - 1][j][1]) % 1000000007;
        ;
      }
      if (a[i] == 0 || a[i] == 4) {
        if (j % 4) {
          if (j >= k) {
            dp[i][4][1] = (dp[i][4][1] + dp[i - 1][j][0]) % 1000000007;
            ;
          } else
            dp[i][4][0] = (dp[i][4][0] + dp[i - 1][j][0]) % 1000000007;
          ;
          dp[i][4][1] = (dp[i][4][1] + dp[i - 1][j][1]) % 1000000007;
          ;
        } else {
          p = min(j + 4, 2048);
          dp[i][p][0] = (dp[i][p][0] + dp[i - 1][j][0]) % 1000000007;
          ;
          dp[i][p][1] = (dp[i][p][1] + dp[i - 1][j][1]) % 1000000007;
          ;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < maxn; i++) {
    ans = (ans + dp[n][i][1]) % 1000000007;
    ;
    if (i >= k) ans = (ans + dp[n][i][0]) % 1000000007;
    ;
  }
  cout << ans;
  return 0;
}
