#include <bits/stdc++.h>
using namespace std;
int dp[2010][(1 << 13) + 10];
int precalc[2010];
int max_val[(1 << 13) + 10];
int min_val[(1 << 13) + 10];
int merge(int mask, int pot) {
  if (pot > min_val[mask]) return (1 << pot);
  if (pot < min_val[mask]) return (mask | (1 << pot));
  int new_mask = mask;
  int now = pot;
  mask ^= (1 << pot);
  while (true) {
    if ((mask >> (now + 1)) & 1) {
      now++;
      mask ^= (1 << now);
    } else {
      mask |= (1 << (now + 1));
      break;
    }
  }
  return mask;
}
int n, k;
int sequence[2010];
int solve(int pos, int mask) {
  if (pos >= n) return 0LL;
  int &ret = dp[pos][mask];
  if (ret != -1) return ret;
  ret = 0;
  if (sequence[pos] == 0) {
    int new_mask = merge(mask, 1);
    int new_mask2 = merge(mask, 2);
    if (max_val[new_mask] >= k)
      ret = precalc[pos + 1] % 1000000007;
    else
      ret = solve(pos + 1, new_mask) % 1000000007;
    if (max_val[new_mask2] >= k)
      ret = (ret % 1000000007 + precalc[pos + 1] % 1000000007) % 1000000007;
    else
      ret = (ret % 1000000007 + solve(pos + 1, new_mask2) % 1000000007) %
            1000000007;
    return ret;
  }
  int new_mask = merge(mask, ((sequence[pos] == 2) ? 1 : 2));
  if (max_val[new_mask] >= k)
    ret = precalc[pos + 1] % 1000000007;
  else
    ret = solve(pos + 1, new_mask) % 1000000007;
  return ret;
}
int pot2[2020];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &sequence[i]);
  pot2[0] = 1;
  for (int i = 1; i < 2010; i++) {
    pot2[i] = (pot2[i - 1] % 1000000007) * 2;
    pot2[i] %= 1000000007;
  }
  int now = 0;
  precalc[n] = 1LL;
  for (int i = n - 1; i >= 0; i--) {
    if (sequence[i] == 0) now++;
    precalc[i] = pot2[now] % 1000000007;
  }
  memset(dp, -1, sizeof(dp));
  for (int mask = 0; mask < (1 << 13); mask++) {
    min_val[mask] = 1 << 30;
    max_val[mask] = -(1 << 30);
    for (int i = 0; i < 13; i++) {
      if ((mask >> i) & 1) {
        min_val[mask] = min(min_val[mask], i);
        max_val[mask] = max(max_val[mask], i);
      }
    }
  }
  printf("%d\n", solve(0, 0) % 1000000007);
  return 0;
}
