#include <bits/stdc++.h>
using namespace std;
int di[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dj[] = {1, -1, 0, 0, 1, -1, 1, -1};
int n, k;
int arr[2005];
long long memo[2005][(1 << 12) + 5];
void rec(int idx, int &msk) {
  if (idx == k) return;
  if (msk & (1 << idx)) {
    rec(idx + 1, msk);
    msk &= (((1 << k) - 1) - (1 << (idx)));
  } else {
    msk |= (1 << (idx));
  }
}
int nMskGen(int idx, int msk) {
  for (int i = 0; i < idx; i++)
    if (msk & (1 << i)) return (1 << idx);
  rec(idx, msk);
  return msk;
}
long long dp(int idx, int msk) {
  if (idx == n) {
    if (msk >= (1 << (k - 1))) return 1;
    return 0;
  }
  long long &ret = memo[idx][msk];
  if (ret != -1) return ret;
  ret = 0;
  if (arr[idx] != 2) {
    int nMsk = (msk & (1 << (k - 1))) ? msk : nMskGen(0, msk);
    ret = (ret + dp(idx + 1, nMsk)) % 1000000007;
  }
  if (arr[idx] != 1) {
    int nMsk = (msk & (1 << (k - 1))) ? msk : nMskGen(1, msk);
    ret = (ret + dp(idx + 1, nMsk)) % 1000000007;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(memo, -1, sizeof memo);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] /= 2;
  }
  cout << dp(0, 0);
  return 0;
}
