#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& t) {
  return in >> t.first >> t.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& t) {
  return out << t.first << " " << t.second << endl;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& t) {
  for (int i = 0; i < t.size(); i++) in >> t[i];
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& t) {
  for (int i = 0; i < t.size(); i++) out << t[i] << " ";
  return out;
}
const int mod = 1e9 + 7;
const int N = 2e3 + 4;
long long dp[N][4 * N][2];
vector<int> v;
int n, k;
int pr;
long long d(int pos, int mask, int w) {
  if (mask >= pr) w = 1;
  if (pos >= v.size()) return w;
  long long& cur = dp[pos][mask][w];
  if (cur) return cur - 1;
  long long add1 = d(pos + 1, mask + 2, w);
  int m2 = 4;
  if (mask % 4 == 0) m2 += mask;
  long long add2 = d(pos + 1, m2, w);
  if (v[pos] != 2) cur = (cur + add2) % mod;
  if (v[pos] != 4) cur = (cur + add1) % mod;
  return cur++;
}
int main() {
  cin >> n >> k;
  v.resize(n);
  cin >> v;
  pr = 1 << k;
  cout << d(0, 0, 0) << endl;
  return 0;
}
