#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gi() {
  T x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int N = 100003, M = N << 1, mod = 1000000007;
int n, p;
long long dp[N][2][2][2];
long long pw[N];
int col[N];
inline void Add(long long &x, long long y) { x = (x + y) % mod; }
int main() {
  n = gi<int>(), p = gi<int>();
  for (int i = (pw[0] = 1); i <= n; i += 1)
    col[i] = gi<int>(), pw[i] = 1ll * pw[i - 1] * 2 % mod;
  dp[0][0][0][0] = 1;
  for (int i = 0; i < n; i += 1)
    for (int j = 0; j <= 1; j += 1)
      for (int x = 0; x <= 1; x += 1)
        for (int y = 0; y <= 1; y += 1) {
          if (col[i + 1] == 1 || col[i + 1] == -1) {
            if (!x)
              Add(dp[i + 1][1 - j][x][1], 1ll * pw[i] * dp[i][j][x][y]);
            else
              Add(dp[i + 1][1 - j][x][1], 1ll * pw[i - 1] * dp[i][j][x][y]),
                  Add(dp[i + 1][j][x][y], 1ll * pw[i - 1] * dp[i][j][x][y]);
          }
          if (col[i + 1] == 0 || col[i + 1] == -1) {
            if (!y)
              Add(dp[i + 1][1 - j][1][y], 1ll * pw[i] * dp[i][j][x][y]);
            else
              Add(dp[i + 1][1 - j][1][y], 1ll * pw[i - 1] * dp[i][j][x][y]),
                  Add(dp[i + 1][j][x][y], 1ll * pw[i - 1] * dp[i][j][x][y]);
          }
        }
  long long ans = 0;
  Add(ans, dp[n][p][0][0]);
  Add(ans, dp[n][p][0][1]);
  Add(ans, dp[n][p][1][0]);
  Add(ans, dp[n][p][1][1]);
  printf("%lld\n", ans);
  return 0;
}
