#include <bits/stdc++.h>
using namespace std;
const int maxn = 2002;
const int maxk = 10;
const int mod = 1000000007;
int a[maxn];
int dp[maxn][(1 << maxk)][maxk + 1];
int wop[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  k--;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] >>= 1;
  }
  wop[0] = 1;
  for (int i = 1; i <= n; ++i) wop[i] = (wop[i - 1] << 1) % mod;
  int zero = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (!a[i]) zero++;
    for (int mask = 0; mask < (1 << k); ++mask)
      for (int j = 0; j <= k; ++j) {
        if (mask >= (1 << j))
          dp[i][mask][j] = wop[zero];
        else if (a[i]) {
          if ((mask & (a[i] - 1)) == 0) {
            int nmask = mask + a[i];
            if (nmask >= (1 << j))
              dp[i][mask][j] = wop[zero];
            else
              dp[i][mask][j] = dp[i + 1][nmask][j];
          } else
            dp[i][mask][j] = dp[i + 1][a[i]][j];
        } else {
          int nmask = mask + 1;
          if (nmask >= (1 << j))
            dp[i][mask][j] = wop[zero - 1];
          else
            dp[i][mask][j] = dp[i + 1][nmask][j];
          if ((mask & 1) == 0) {
            int nmask = mask + 2;
            if (nmask >= (1 << j))
              dp[i][mask][j] += wop[zero - 1];
            else
              dp[i][mask][j] += dp[i + 1][nmask][j];
          } else
            dp[i][mask][j] += dp[i + 1][2][j];
        }
        dp[i][mask][j] %= mod;
      }
  }
  cout << dp[0][0][k] << endl;
  return 0;
}
