#include <bits/stdc++.h>
const int N = 3e3 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double PI = acos(-1), EPS = 1e-9;
using namespace std;
namespace fast_IO {
long long read() {
  long long x = 0;
  char c;
  bool flag = false;
  while ((c = getchar()) == ' ' || c == '\n' || c == '\r')
    ;
  if (c == '-')
    flag = true;
  else
    x = c ^ 48;
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48);
  if (flag) return -x;
  return x;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 ^ 48);
}
}  // namespace fast_IO
int a[N], dp[N][N][2];
int main() {
  int n = fast_IO::read(), k = fast_IO::read();
  for (int i = 1; i <= n; ++i) a[i] = fast_IO::read();
  int ans = 0;
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2050; ++j) {
      if (a[i] == 0 || a[i] == 2) {
        int now = min(2049, j + 2);
        (dp[i][now][1] += dp[i - 1][j][1]) %= mod;
        (dp[i][now][0] += dp[i - 1][j][0]) %= mod;
      }
      if (a[i] == 0 || a[i] == 4) {
        int now = min(2049, j + 4);
        if (j % 4) {
          if (j >= (1 << k))
            (dp[i][4][1] += dp[i - 1][j][0]) %= mod;
          else
            (dp[i][4][0] += dp[i - 1][j][0]) %= mod;
          (dp[i][4][1] += dp[i - 1][j][1]) %= mod;
        } else {
          (dp[i][now][1] += dp[i - 1][j][1]) %= mod;
          (dp[i][now][0] += dp[i - 1][j][0]) %= mod;
        }
      }
    }
  }
  for (int i = 0; i < 2050; ++i) {
    (ans += dp[n][i][1]) %= mod;
    if (i >= (1 << k)) (ans += dp[n][i][0]) %= mod;
  }
  printf("%d", ans);
  return 0;
}
