#include <bits/stdc++.h>
using namespace std;
inline long long minOf(long long x, long long y) { return (x < y ? x : y); }
inline long long maxOf(long long x, long long y) { return (x > y ? x : y); }
inline long long mabs(long long x) { return (x < 0 ? -x : x); }
long long dp[2002][3000];
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int l[2002];
  int cumu[2002] = {0};
  long long pow2[2500];
  pow2[0] = 1;
  for (int i = 1; i <= 2000; i++) {
    pow2[i] = pow2[i - 1] * 2LL;
    if (pow2[i] >= 1000000007) pow2[i] %= 1000000007;
  }
  for (int i = 1; i <= n; i++) cin >> l[i];
  for (int i = n; i >= 1; i--) {
    cumu[i] = cumu[i + 1];
    if (l[i] == 0) cumu[i]++;
  }
  long long ans = 0;
  int limit = (1 << k);
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 2; j <= limit + 2; j += 2) {
      if (j == limit) continue;
      if (l[i] == 0) {
        if (j >= 2 && dp[i - 1][j - 2]) dp[i][j] += dp[i - 1][j - 2];
        if (j >= 4 && dp[i - 1][j - 4]) {
          if (!(j & 2))
            dp[i][j] += dp[i - 1][j - 4];
          else {
            dp[i][4] += dp[i - 1][j - 4];
            if (dp[i][4] >= 1000000007) dp[i][4] %= 1000000007;
          }
        }
        if (dp[i][j] >= 1000000007) dp[i][j] %= 1000000007;
      } else if (j >= l[i] && !(j & (l[i] >> 1)))
        dp[i][j] += dp[i - 1][j - l[i]];
      else if (j >= l[i])
        dp[i][l[i]] += dp[i - 1][j - l[i]];
    }
    if (l[i] == 0) {
      if (dp[i - 1][limit - 2]) {
        ans = ans + dp[i - 1][limit - 2] * pow2[cumu[i + 1]];
        if (ans >= 1000000007) ans %= 1000000007;
      }
      if (dp[i - 1][limit - 4]) {
        ans = ans + dp[i - 1][limit - 4] * pow2[cumu[i + 1]];
        if (ans >= 1000000007) ans %= 1000000007;
      }
    } else {
      if (dp[i - 1][limit - l[i]]) {
        ans = ans + dp[i - 1][limit - l[i]] * pow2[cumu[i + 1]];
        if (ans >= 1000000007) ans %= 1000000007;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
