#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long s = 0, w = 1;
  char c;
  while (c = getchar(), c > '9' || c < '0')
    if (c == '-') w = -1;
  while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
  return s * w;
}
const long long md = 1000000007;
long long n, p, f[2][2][2], g[2][2][2], B, BB;
inline void Ad(long long &x, long long y) {
  x = (x + y);
  x -= (x >= md) ? md : 0;
}
signed main() {
  long long t, i, j, k, x, re = 0LL;
  n = read();
  p = read();
  x = read();
  B = 1LL;
  BB = 2LL;
  if (x != 1) g[1][1][0] = 1LL;
  if (x != 0) g[1][0][1] = 1LL;
  memmove(f, g, sizeof f);
  for (t = 2; t <= n; t++) {
    x = read();
    memset(f, 0, sizeof f);
    if (x != 1) {
      for (i = 0; i <= 1; i++) {
        for (j = 0; j <= 1; j++) {
          for (k = 0; k <= 1; k++) {
            if (k) {
              Ad(f[i][j][k], g[i][j][k] * B % md);
              Ad(f[i ^ 1][1][k], g[i][j][k] * B % md);
            } else
              Ad(f[i ^ 1][1][k], g[i][j][k] * BB % md);
          }
        }
      }
    }
    if (x != 0) {
      for (i = 0; i <= 1; i++) {
        for (j = 0; j <= 1; j++) {
          for (k = 0; k <= 1; k++) {
            if (j) {
              Ad(f[i][j][k], g[i][j][k] * B % md);
              Ad(f[i ^ 1][j][1], g[i][j][k] * B % md);
            } else
              Ad(f[i ^ 1][j][1], g[i][j][k] * BB % md);
          }
        }
      }
    }
    B = BB;
    BB = (B << 1) % md;
    for (i = 0; i <= 1; i++)
      for (j = 0; j <= 1; j++)
        for (k = 0; k <= 1; k++) g[i][j][k] = f[i][j][k] % md;
  }
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++) Ad(re, f[p][i][j]);
  printf("%lld\n", re);
}
