#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1e9 + 7;
const int MAX = 2e3 + 10;
long long dp[MAX][2050];
int n, k;
int v[MAX], sulf[MAX];
long long expo[MAX];
int val;
int add(int a, int b) {
  if (b > (a & -a)) return b;
  return a + b;
}
long long solve(int i, int x) {
  if (x >= val) return expo[sulf[i]];
  if (i == n) return 0;
  auto& ans = dp[i][x];
  if (ans + 1) return ans;
  if (v[i]) return ans = solve(i + 1, add(x, v[i]));
  ans = 0;
  ans = (ans + solve(i + 1, add(x, 2))) % MOD;
  ans = (ans + solve(i + 1, add(x, 4))) % MOD;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  expo[0] = 1;
  for (int i = 1; i < MAX; i++) expo[i] = 2 * expo[i - 1] % MOD;
  cin >> n >> k;
  val = (1 << k);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = n - 1; i >= 0; i--) sulf[i] = sulf[i + 1] + (v[i] == 0);
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0) << '\n';
  exit(0);
}
