#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX_N = 2005;
int dp[MAX_N][MAX_N], ways[MAX_N], num[MAX_N];
int n, k;
int Solve(int x, int m) {
  if (x > n) return 0;
  if (m == k) {
    dp[x][m] = ways[x];
  }
  if (dp[x][m] != -1) {
    return dp[x][m];
  }
  dp[x][m] = 0;
  if (num[x] != 2) {
    dp[x][m] += Solve(x + 1, m + 1);
    dp[x][m] %= MOD;
  }
  if (num[x] != 4 && num[x + 1] != 4) {
    dp[x][m] += Solve(x + 2, m + 1);
    dp[x][m] %= MOD;
  }
  if (num[x] != 4 && num[x + 1] != 2) {
    dp[x][m] += Solve(x + 2, 1);
    dp[x][m] %= MOD;
  }
  return dp[x][m];
}
int main() {
  while (cin >> n >> k) {
    memset(dp, -1, sizeof(dp));
    k = (1 << k) / 4;
    for (int i = 0; i < n; i++) {
      cin >> num[i];
    }
    ways[n] = 1;
    for (int i = n - 1; i >= 0; i--) {
      ways[i] = ways[i + 1] * ((num[i] == 0) ? 2 : 1);
      ways[i] %= MOD;
    }
    cout << Solve(0, 0) << endl;
  }
  return 0;
}
