#include <bits/stdc++.h>
using namespace std;
long long int modulo = 1e9 + 7;
int n, k;
long long int maneras[2001][1 << 12];
void siguiente(int i, int val) {
  for (int c = 0; c < 1 << k; c++) {
    if ((c & 2) and val == 4)
      maneras[i][4] = (maneras[i][4] + maneras[i - 1][c]) % modulo;
    else {
      int nextc = c + val;
      maneras[i][nextc] = (maneras[i][nextc] + maneras[i - 1][c]) % modulo;
    }
  }
  maneras[i][1 << k] = (maneras[i][1 << k] + maneras[i - 1][1 << k]) % modulo;
}
int main() {
  cin >> n >> k;
  maneras[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x == 0) {
      siguiente(i, 2);
      siguiente(i, 4);
    } else if (x == 2)
      siguiente(i, 2);
    else
      siguiente(i, 4);
  }
  cout << maneras[n][1 << k] << endl;
}
