#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 11) + 10;
const int MOD = 1000000007;
int dp[N][N], ways[N];
int a[N], n, wanted;
int f(const int i, const int k) {
  int& r = dp[i][k];
  if (r != -1) return r;
  if (k == wanted) return r = ways[i];
  if (i == n) return r = 0;
  r = 0;
  if (a[i] != 2) r = (r + f(i + 1, k + 1)) % MOD;
  if (a[i] != 4 && a[i + 1] != 4 && i + 1 < n) r = (r + f(i + 2, k + 1)) % MOD;
  if (a[i] != 4 && a[i + 1] != 2 && i + 1 < n) r = (r + f(i + 2, 1)) % MOD;
  return r;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> wanted;
  wanted = (1 << (wanted - 2));
  for (int i = 0; i < n; ++i) cin >> a[i];
  ways[n] = 1;
  for (int i = n - 1; i >= 0; --i)
    ways[i] = (ways[i + 1] * (a[i] != 0 ? 1 : 2)) % MOD;
  cout << f(0, 0) << endl;
  return 0;
}
