#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
const int mod = (int)1e9 + 7;
int dp[2][1 << 11];
int n, m, a[2000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)n; i++) cin >> a[i];
  dp[0][0] = 1;
  int cur = 0, next = 1;
  for (int i = 0; i < (int)n; i++) {
    memset(dp[next], 0, sizeof(dp[next]));
    for (int j = 0; j < (int)1 << m; j++)
      for (int k = 0; k < (int)2; k++) {
        if (a[i] && (1 << k + 1) != a[i]) continue;
        if (dp[cur][j] == 0) continue;
        int nj = j;
        if (j < (1 << m - 1) && (j & 1) && k == 1)
          nj = 2;
        else
          nj += 1 << k;
        if (nj >= 1 << m - 1) nj = 1 << m - 1;
        (dp[next][nj] += dp[cur][j]) %= mod;
      }
    swap(cur, next);
  }
  cout << dp[cur][1 << m - 1] << endl;
  return 0;
}
