#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, k, k2, a[2005], f[2005][(1 << 11) + 5];
inline void read(int &num) {
  num = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    num = (num << 1) + (num << 3) + (ch ^ 48), ch = getchar();
}
int main() {
  read(n);
  read(k);
  k2 = 1 << k;
  f[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    for (int j = 0; j <= k2; j += 2) {
      if (a[i] == 2 || a[i] == 0) {
        f[i][min(j + 2, k2)] += f[i - 1][j];
        f[i][min(j + 2, k2)] %= MOD;
      }
      if (a[i] == 4 || a[i] == 0) {
        if (j % 4) {
          f[i][4] += f[i - 1][j];
          f[i][4] %= MOD;
        } else {
          f[i][min(j + 4, k2)] += f[i - 1][j];
          f[i][min(j + 4, k2)] %= MOD;
        }
      }
    }
  }
  printf("%d", f[n][k2]);
  return 0;
}
