#include <bits/stdc++.h>
using namespace std;
long long DP[2005][4100][2], n, k, a[2005];
void reset() {
  for (long long(i) = (1); (i) <= (n); (i)++) {
    for (long long(j) = (0); (j) <= (1 << 12); (j)++) {
      DP[i][j][0] = -1;
      DP[i][j][1] = -1;
    }
  }
}
long long dp(int i, int bit, bool done) {
  if (bit >= k) {
    bit = 0;
    done = 1;
  }
  if (i == n + 1) {
    return done;
  } else if (DP[i][bit][done] != -1) {
    return DP[i][bit][done];
  } else {
    long long total = 0;
    if (a[i] == 0) {
      total += dp(i + 1, bit + 2, done);
      total %= 1000000007;
      if (bit & 2) {
        total += dp(i + 1, 4, done);
      } else {
        total += dp(i + 1, bit + 4, done);
      }
    } else {
      if (a[i] == 2) {
        total += dp(i + 1, bit + 2, done);
      } else {
        if (bit & 2) {
          total += dp(i + 1, 4, done);
        } else {
          total += dp(i + 1, bit + 4, done);
        }
      }
    }
    total %= 1000000007;
    return DP[i][bit][done] = total;
  }
}
void input() {
  cin >> n >> k;
  k = 1 << k;
  for (long long(i) = (1); (i) <= (n); (i)++) {
    cin >> a[i];
  }
}
void solve() { cout << dp(1, 0, 0) << endl; }
void LetsRock() { solve(); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  input();
  reset();
  solve();
  return 0;
}
