#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int dp[2005][(1 << 10) + 5], a[2005];
int main() {
  int T, i, ca = 0, m, j, k, n;
  int l, r;
  while (~scanf("%d%d", &n, &k)) {
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    memset(dp[0], 0, sizeof(dp[0]));
    if (a[0] == 0)
      dp[0][1] = dp[0][2] = 1;
    else if (a[0] == 2)
      dp[0][1] = 1;
    else
      dp[0][2] = 1;
    int now = 0;
    int st = 1 << (k - 1);
    for (i = 1; i < n; i++) {
      memset(dp[1 - now], 0, sizeof(dp[0]));
      for (j = 0; j <= st; j++)
        if (dp[now][j]) {
          if (a[i] == 2 || a[i] == 0) {
            if (j + 1 < st)
              (dp[1 - now][j + 1] += dp[now][j]) %= 1000000007;
            else
              (dp[1 - now][st] += dp[now][j]) %= 1000000007;
          }
          if (a[i] == 4 || a[i] == 0) {
            if (!(j & 1)) {
              if (j + 2 < st)
                (dp[1 - now][j + 2] += dp[now][j]) %= 1000000007;
              else
                (dp[1 - now][st] += dp[now][j]) %= 1000000007;
            } else
              (dp[1 - now][2] += dp[now][j]) %= 1000000007;
          }
        }
      now = 1 - now;
    }
    printf("%d\n", dp[now][st]);
  }
  return 0;
}
