#include <bits/stdc++.h>
using namespace std;
static long long m1[2048][2048];
int main() {
  ios_base::sync_with_stdio(0);
  long long n, m, a, b;
  cin >> n >> m;
  m1[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    if (a == 2)
      for (int j = 0; j < (1 << m); ++j)
        m1[i + 1][min(j + 1, (1 << m) - 1)] =
            (m1[i + 1][min(j + 1, (1 << m) - 1)] + m1[i][j]) %
            (long long)1000000007;
    else if (a == 4) {
      b = 0;
      for (int j = 0; j < (1 << m); j += 2) {
        m1[i + 1][min(j + 2, (1 << m) - 1)] =
            (m1[i + 1][min(j + 2, (1 << m) - 1)] + m1[i][j]) %
            (long long)1000000007;
        if (j + 1 < (1 << (m - 1)))
          b = (b + m1[i][j + 1]) % (long long)1000000007;
        else
          m1[i + 1][j + 1] =
              (m1[i + 1][j + 1] + m1[i][j + 1]) % (long long)1000000007;
      }
      m1[i + 1][2] = (m1[i + 1][2] + b) % (long long)1000000007;
    } else {
      b = 0;
      for (int j = 0; j < (1 << m); ++j)
        m1[i + 1][min(j + 1, (1 << m) - 1)] =
            (m1[i + 1][min(j + 1, (1 << m) - 1)] + m1[i][j]) %
            (long long)1000000007;
      for (int j = 0; j < (1 << m); j += 2) {
        m1[i + 1][min(j + 2, (1 << m) - 1)] =
            (m1[i + 1][min(j + 2, (1 << m) - 1)] + m1[i][j]) %
            (long long)1000000007;
        if (j + 1 < (1 << (m - 1)))
          b = (b + m1[i][j + 1]) % (long long)1000000007;
        else
          m1[i + 1][j + 1] =
              (m1[i + 1][j + 1] + m1[i][j + 1]) % (long long)1000000007;
      }
      m1[i + 1][2] = (m1[i + 1][2] + b) % (long long)1000000007;
    }
  }
  long long res = 0;
  for (int i = 0; i < (1 << (m - 1)); ++i)
    res = (res + m1[n][i + (1 << (m - 1))]) % (long long)1000000007;
  cout << res << endl;
  return 0;
}
