#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[2010];
const int mod = 1e9 + 7;
int dp[2010][4000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (arr[0] == 0) {
    dp[0][2] = 1;
    dp[0][1] = 1;
  } else if (arr[0] == 2) {
    dp[0][1] = 1;
  } else if (arr[0] == 4) {
    dp[0][2] = 1;
  }
  dp[0][0] = 1;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= (1 << (m - 1)); j++) {
      if (dp[i - 1][j]) {
        if (j == (1 << (m - 1))) {
          if (arr[i] != 4) dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod;
          if (arr[i] != 2) dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod;
          continue;
        }
        if (arr[i] != 4) {
          int next = j + 1;
          dp[i][next] += dp[i - 1][j];
          dp[i][next] %= mod;
        }
        if (arr[i] != 2) {
          if (j % 2 == 0) {
            int next = j + 2;
            dp[i][next] += dp[i - 1][j];
            dp[i][next] %= mod;
          } else {
            int next = 2;
            dp[i][next] += dp[i - 1][j];
            dp[i][next] %= mod;
          }
        }
      }
    }
  }
  cout << dp[n - 1][(1 << (m - 1))] << endl;
  return 0;
}
