#include <bits/stdc++.h>
using namespace std;
int n, k;
int data[10009];
long long mem[2009][1 << 13][2];
long long modpow(long long base, long long power) {
  long long ret = 1;
  while (power > 0) {
    if (power % 2 == 1) {
      ret = (ret * base) % (1000000007LL);
    }
    power = power >> 1;
    base = (base * base) % (1000000007LL);
  }
  return ret;
}
long long dp(int i, int bit, int flag) {
  if (i == n) {
    return flag;
  }
  long long &ret = mem[i][bit][flag];
  if (ret > -1) return ret;
  ret = 0;
  if (flag == 1) {
    int c = 0;
    for (int j = i; j < n; j++) {
      if (data[j] == 0) c++;
    }
    ret = (modpow(2, c));
    return ret;
  }
  int val = data[i];
  if (data[i] == 0) {
    val = 2;
    int nbit = bit;
    for (long long j = 0; j < (long long)13; j++) {
      if (((nbit >> j) & 1)) {
        if ((1 << j) == val) {
          nbit = (nbit & (~(1 << j)));
          val = 2 * val;
        } else {
          if ((1 << j) < val) {
            nbit = 0;
            break;
          } else {
            break;
          }
        }
      }
    }
    nbit = nbit | val;
    int nflag = flag;
    if (val >= (1 << k)) {
      nflag = 1;
      nbit = 0;
    }
    ret += dp(i + 1, nbit, nflag);
    ret = ret % (1000000007LL);
    val = 4;
    nbit = bit;
    for (long long j = 0; j < (long long)13; j++) {
      if (((nbit >> j) & 1)) {
        if ((1 << j) == val) {
          nbit = (nbit & (~(1 << j)));
          val = 2 * val;
        } else {
          if ((1 << j) < val) {
            nbit = 0;
            break;
          } else {
            break;
          }
        }
      }
    }
    nbit = nbit | val;
    nflag = flag;
    if (val >= (1 << k)) {
      nflag = 1;
      nbit = 0;
    }
    ret += dp(i + 1, nbit, nflag);
    ret = ret % (1000000007LL);
  } else if (data[i] == 2) {
    val = 2;
    int nbit = bit;
    for (long long j = 0; j < (long long)13; j++) {
      if (((nbit >> j) & 1)) {
        if ((1 << j) == val) {
          nbit = (nbit & (~(1 << j)));
          val = 2 * val;
        } else {
          if ((1 << j) < val) {
            nbit = 0;
            break;
          } else {
            break;
          }
        }
      }
    }
    nbit = nbit | val;
    int nflag = flag;
    if (val >= (1 << k)) {
      nflag = 1;
      nbit = 0;
    }
    ret += dp(i + 1, nbit, nflag);
    ret = ret % (1000000007LL);
  } else {
    val = 4;
    int nbit = bit;
    for (long long j = 0; j < (long long)13; j++) {
      if (((nbit >> j) & 1)) {
        if ((1 << j) == val) {
          nbit = (nbit & (~(1 << j)));
          val = 2 * val;
        } else {
          if ((1 << j) < val) {
            nbit = 0;
            break;
          } else {
            break;
          }
        }
      }
    }
    nbit = nbit | val;
    int nflag = flag;
    if (val >= (1 << k)) {
      nflag = 1;
      nbit = 0;
    }
    ret += dp(i + 1, nbit, nflag);
    ret = ret % (1000000007LL);
  }
  ret = ret % (1000000007LL);
  return ret;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &k);
  for (long long i = 0; i < (long long)n; i++) {
    scanf("%d", &data[i]);
  }
  memset(mem, -1, sizeof mem);
  long long ret = dp(0, 0, 0);
  ret = (ret + (1000000007LL)) % (1000000007LL);
  cout << ret << endl;
}
