#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void ckmax(T& x, T y) {
  x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
  x = (y < x ? y : x);
}
namespace Fread {
const int SIZE = 1 << 21;
char buf[SIZE], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, SIZE, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
namespace Fwrite {
const int SIZE = 1 << 21;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() {
  fwrite(buf, 1, S - buf, stdout);
  S = buf;
}
inline void putchar(char c) {
  *S++ = c;
  if (S == T) flush();
}
struct NTR {
  ~NTR() { flush(); }
} ztr;
}  // namespace Fwrite
namespace Fastio {
struct Reader {
  template <typename T>
  Reader& operator>>(T& x) {
    char c = Fread ::getchar();
    T f = 1;
    while (c < '0' || c > '9') {
      if (c == '-') f = -1;
      c = Fread ::getchar();
    }
    x = 0;
    while (c >= '0' && c <= '9') {
      x = x * 10 + (c - '0');
      c = Fread ::getchar();
    }
    x *= f;
    return *this;
  }
  Reader& operator>>(char& c) {
    c = Fread ::getchar();
    while (c == '\n' || c == ' ') c = Fread ::getchar();
    return *this;
  }
  Reader& operator>>(char* str) {
    int len = 0;
    char c = Fread ::getchar();
    while (c == '\n' || c == ' ') c = Fread ::getchar();
    while (c != '\n' && c != ' ') {
      str[len++] = c;
      c = Fread ::getchar();
    }
    str[len] = '\0';
    return *this;
  }
  Reader() {}
} cin;
const char endl = '\n';
struct Writer {
  template <typename T>
  Writer& operator<<(T x) {
    if (x == 0) {
      Fwrite ::putchar('0');
      return *this;
    }
    if (x < 0) {
      Fwrite ::putchar('-');
      x = -x;
    }
    static int sta[45];
    int top = 0;
    while (x) {
      sta[++top] = x % 10;
      x /= 10;
    }
    while (top) {
      Fwrite ::putchar(sta[top] + '0');
      --top;
    }
    return *this;
  }
  Writer& operator<<(char c) {
    Fwrite ::putchar(c);
    return *this;
  }
  Writer& operator<<(char* str) {
    int cur = 0;
    while (str[cur]) Fwrite ::putchar(str[cur++]);
    return *this;
  }
  Writer& operator<<(const char* str) {
    int cur = 0;
    while (str[cur]) Fwrite ::putchar(str[cur++]);
    return *this;
  }
  Writer() {}
} cout;
}  // namespace Fastio
const int MAXN = 1e5;
const int MOD = 1e9 + 7;
inline int mod1(int x) { return x < MOD ? x : x - MOD; }
inline int mod2(int x) { return x < 0 ? x + MOD : x; }
inline void add(int& x, int y) { x = mod1(x + y); }
inline void sub(int& x, int y) { x = mod2(x - y); }
int n, goal, a[MAXN + 5];
int pw2[MAXN + 5];
int dp[MAXN + 5][2][2][2];
inline int calc0(int i, int have_1) {
  if (have_1) assert(i);
  return have_1 ? pw2[i - 1] : pw2[i];
}
inline int calc1(int i, int have_1) {
  if (have_1) assert(i);
  return have_1 ? pw2[i - 1] : 0;
}
int main() {
  Fastio ::cin >> n >> goal;
  for (int i = 1; i <= n; ++i) {
    Fastio ::cin >> a[i];
  }
  pw2[0] = 1;
  for (int i = 1; i <= n; ++i) pw2[i] = pw2[i - 1] * 2 % MOD;
  dp[0][0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int have_r1 = 0; have_r1 <= 1; ++have_r1) {
      for (int have_b1 = 0; have_b1 <= 1; ++have_b1) {
        for (int s = 0; s <= 1; ++s)
          if (dp[i - 1][have_r1][have_b1][s]) {
            if (a[i] != 1) {
              add(dp[i][have_r1][have_b1][s],
                  (long long)dp[i - 1][have_r1][have_b1][s] *
                      calc1(i - 1, have_b1) % MOD);
              add(dp[i][have_r1 | 1][have_b1][s ^ 1],
                  (long long)dp[i - 1][have_r1][have_b1][s] *
                      calc0(i - 1, have_b1) % MOD);
            }
            if (a[i] != 0) {
              add(dp[i][have_r1][have_b1][s],
                  (long long)dp[i - 1][have_r1][have_b1][s] *
                      calc1(i - 1, have_r1) % MOD);
              add(dp[i][have_r1][have_b1 | 1][s ^ 1],
                  (long long)dp[i - 1][have_r1][have_b1][s] *
                      calc0(i - 1, have_r1) % MOD);
            }
          }
      }
    }
  }
  int ans = 0;
  for (int have_r1 = 0; have_r1 <= 1; ++have_r1) {
    for (int have_b1 = 0; have_b1 <= 1; ++have_b1) {
      add(ans, dp[n][have_r1][have_b1][goal]);
    }
  }
  Fastio ::cout << ans << Fastio ::endl;
  return 0;
}
