#include <bits/stdc++.h>
using namespace std;
long long pd[2000][1 << 11 + 1][2];
int v[2000];
int n, k;
int makemask(int mask, int val) {
  if (val == 2)
    mask += 2;
  else {
    if (mask & 2)
      mask = 4;
    else
      mask += 4;
  }
  mask = min(mask, 2048);
  return mask;
}
long long solve(int curr, int mask, bool ok) {
  bool cok = ok;
  if (mask >= (1 << k)) cok = true;
  if (curr == n) return cok;
  long long &ans = pd[curr][mask][ok];
  if (ans == -1) {
    if (v[curr])
      ans = solve(curr + 1, makemask(mask, v[curr]), cok);
    else {
      ans = (solve(curr + 1, makemask(mask, 2), cok) +
             solve(curr + 1, makemask(mask, 4), cok)) %
            1000000007;
    }
  }
  return ans;
}
int main(void) {
  int i;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> v[i];
  memset(pd, -1, sizeof pd);
  cout << solve(0, 0, false) << endl;
}
