#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
int n, type;
int a[N], bit[N], f[N][2][2][2];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline void add(int &x, int y) {
  x += y;
  while (x >= mod) x -= mod;
}
int main() {
  read(n);
  read(type);
  for (int i = 1; i <= n; ++i) read(a[i]);
  bit[0] = 1;
  for (int i = 1; i <= n; ++i) bit[i] = 1LL * bit[i - 1] * 2 % mod;
  f[0][0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int tp = 0; tp <= 1; ++tp) {
      for (int ob = 0; ob <= 1; ++ob) {
        for (int ow = 0; ow <= 1; ++ow) {
          if (a[i] != 0) {
            if (ob) {
              add(f[i][tp][ob][ow],
                  1LL * f[i - 1][tp][ob][ow] * bit[i - 2] % mod);
              add(f[i][tp ^ 1][ob][ow | 1],
                  1LL * f[i - 1][tp][ob][ow] * bit[i - 2] % mod);
            } else
              add(f[i][tp ^ 1][ob][ow | 1],
                  1LL * f[i - 1][tp][ob][ow] * bit[i - 1] % mod);
          }
          if (a[i] != 1) {
            if (ow) {
              add(f[i][tp][ob][ow],
                  1LL * f[i - 1][tp][ob][ow] * bit[i - 2] % mod);
              add(f[i][tp ^ 1][ob | 1][ow],
                  1LL * bit[i - 2] * f[i - 1][tp][ob][ow] % mod);
            } else
              add(f[i][tp ^ 1][ob | 1][ow],
                  1LL * f[i - 1][tp][ob][ow] * bit[i - 1] % mod);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 1; ++i)
    for (int j = 0; j <= 1; ++j) add(ans, f[n][type][i][j]);
  printf("%d\n", ans);
  return 0;
}
