#include <bits/stdc++.h>
static char s[1 << 20 | 1] = {0}, *p1 = s, *p2 = s;
inline char gc() {
  return (p1 == p2) && (p2 = (p1 = s) + fread(s, 1, 1 << 20, stdin), p1 == p2)
             ? EOF
             : *(p1++);
}
inline int read() {
  int ret = 0;
  bool flag = 0;
  char c = gc();
  while ((c < '0') | (c > '9')) flag ^= !(c ^ '-'), c = gc();
  while ((c >= '0') & (c <= '9'))
    ret = (ret << 1) + (ret << 3) + (c ^ '0'), c = gc();
  return flag ? -ret : ret;
}
const int MaxN = 2e5 + 11;
const int P = 1e9 + 7;
int Po[MaxN] = {1}, Dp[MaxN][2][2][2], A[MaxN];
int n, ans;
inline int Mul(int x, int y) { return (long long)x * y % P; }
inline int Add(int x, int y) { return (x += y) >= P ? x - P : x; }
inline void Inc(int& x, int y) { x += y, x -= (x >= P) ? P : 0; }
inline int c(int i, int g, int opt) {
  if ((!i) && g) return 0;
  if (opt) {
    if (!g) return 0;
    return Po[i - 1];
  }
  if (!g) return Po[i];
  return Po[i - 1];
}
int main(void) {
  int opt;
  n = read(), opt = read();
  for (int i = 1; i <= n; ++i) Po[i] = Mul(Po[i - 1], 2), A[i] = read();
  Po[n + 1] = 0;
  Dp[0][0][0][0] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j <= 1; ++j)
      for (int k = 0; k <= 1; ++k)
        for (int h = 0; h <= 1; ++h) {
          if (A[i + 1] != 1)
            Inc(Dp[i + 1][j][k][h], Mul(Dp[i][j][k][h], Po[k ? i - 1 : n + 1])),
                Inc(Dp[i + 1][1][k][h ^ 1],
                    Mul(Dp[i][j][k][h], Po[k ? i - 1 : i]));
          if (A[i + 1])
            Inc(Dp[i + 1][j][k][h], Mul(Dp[i][j][k][h], Po[j ? i - 1 : n + 1])),
                Inc(Dp[i + 1][j][1][h ^ 1],
                    Mul(Dp[i][j][k][h], Po[j ? i - 1 : i]));
        }
  ans = Add(Add(Dp[n][0][0][opt], Dp[n][0][1][opt]),
            Add(Dp[n][1][1][opt], Dp[n][1][0][opt]));
  printf("%d\n", ans);
  return 0;
}
