#include <bits/stdc++.h>
using std::min;
int n, k, f[2057][2] = {0, 1};
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; n--; i = !i) {
    int x, xx = 1 << k;
    scanf("%d", &x);
    for (int j = 0; j <= xx; ++j) f[j][i] = 0;
    for (int j = 0; j <= xx; ++j) {
      int yy = !(i % 2), zz = j / 2 % 2;
      if (x != 4) (f[min(j + 2, xx)][i] += f[j][yy]) %= 1000000007;
      if (x != 2) (f[zz ? 4 : min(j + 4, xx)][i] += f[j][yy]) %= 1000000007;
    }
    if (!n) printf("%d\n", f[xx][i]);
  }
  return 0;
}
