#include <bits/stdc++.h>
using namespace std;
static const int MOD = 1000000007;
int main() {
  int n, K, val;
  cin >> n >> K;
  --K;
  int sz = (1 << K) + 1;
  vector<int> dp(sz), tmp(sz);
  vector<vector<int>> vals{{1, 2}, {}, {1}, {}, {2}};
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    cin >> val;
    for (int k : vals[val]) {
      for (int j = 0; j < sz; ++j) {
        if (j & (k - 1)) {
          tmp[k] = (tmp[k] + dp[j]) % MOD;
        } else {
          int newVal = j + k;
          if (newVal >= sz) newVal = sz - 1;
          tmp[newVal] = (tmp[newVal] + dp[j]) % MOD;
        }
      }
    }
    dp = move(tmp);
    tmp.assign(sz, 0);
  }
  cout << dp[sz - 1] << endl;
}
