#include <bits/stdc++.h>
using namespace std;
int d[2005][3005], a[10050];
int M = int(1e9 + 7), n, k;
long long ans;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  d[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (1 << 11); j++) {
      if (d[i][j] > 0) {
        if (a[i] == 2 || a[i] == 0) {
          if ((j + 2) >= (1 << k)) {
            long long res = d[i][j];
            for (int e = i + 1; e < n; e++)
              if (a[e] == 0) {
                res *= 2;
                res %= M;
              }
            ans += res;
            ans %= M;
          } else {
            d[i + 1][j + 2] += d[i][j];
            d[i + 1][j + 2] %= M;
          }
        }
        if (a[i] == 4 || a[i] == 0) {
          if (j % 4 == 2) {
            d[i + 1][4] += d[i][j];
            d[i + 1][4] %= M;
          } else {
            if ((j + 4) >= (1 << k)) {
              long long res = d[i][j];
              for (int e = i + 1; e < n; e++)
                if (a[e] == 0) {
                  res *= 2;
                  res %= M;
                }
              ans += res;
              ans %= M;
            } else {
              d[i + 1][j + 4] += d[i][j];
              d[i + 1][j + 4] %= M;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  cin >> n;
}
