#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
void sets() {}
long long f[60][4][3][3], a[60], mi[60], n, m, ans;
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  f[0][0][0][0] = 1;
  mi[0] = 1;
  for (long long i = 1; i <= n; i++) mi[i] = (mi[i - 1] * 2) % mod;
  for (long long i = 1; i <= n; i++) {
    for (long long _ = 0; _ <= 1; _++) {
      for (long long bl = 0; bl <= 1; bl++) {
        for (long long wi = 0; wi <= 1; wi++) {
          if (a[i] != 1) {
            if (bl) {
              f[i][_][bl][wi] =
                  (f[i][_][bl][wi] + f[i - 1][_][bl][wi] * mi[i - 2] % mod) %
                  mod;
              f[i][_ ^ 1][bl][wi | 1] =
                  (f[i][_ ^ 1][bl][wi | 1] +
                   f[i - 1][_][bl][wi] * mi[i - 2] % mod) %
                  mod;
            } else
              f[i][_ ^ 1][bl][wi | 1] =
                  (f[i][_ ^ 1][bl][wi | 1] +
                   f[i - 1][_][bl][wi] * mi[i - 1] % mod) %
                  mod;
          }
          if (a[i] != 0) {
            if (wi) {
              f[i][_][bl][wi] =
                  (f[i][_][bl][wi] + f[i - 1][_][bl][wi] * mi[i - 2] % mod) %
                  mod;
              f[i][_ ^ 1][bl | 1][wi] =
                  (f[i][_ ^ 1][bl | 1][wi] +
                   f[i - 1][_][bl][wi] * mi[i - 2] % mod) %
                  mod;
            } else
              f[i][_ ^ 1][bl | 1][wi] =
                  (f[i][_ ^ 1][bl | 1][wi] +
                   f[i - 1][_][bl][wi] * mi[i - 1] % mod) %
                  mod;
          }
        }
      }
    }
  }
  for (long long bl = 0; bl <= 1; bl++) {
    for (long long wi = 0; wi <= 1; wi++) {
      ans = (ans + f[n][m][bl][wi]) % mod;
    }
  }
  cout << ans;
}
