#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
int n, opt, dat[MAXN], f[MAXN][2][2][2], p[MAXN];
inline int read() {
  int x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    ch == '-' && (f = -1);
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline void Add(int &x, int y) { x += y, x >= MOD && (x -= MOD); }
int main() {
  n = read(), opt = read(), p[0] = 1;
  for (int i = 1; i <= n; i++) dat[i] = read();
  for (int i = 1; i <= n; i++) p[i] = add(p[i - 1], p[i - 1]);
  f[0][0][0][0] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++)
        for (int l = 0; l < 2; l++) {
          if (!f[i][j][k][l]) continue;
          if (dat[i + 1] != 1)
            f[i + 1][j][k][l] =
                (f[i + 1][j][k][l] +
                 1ll * f[i][j][k][l] * (j == 0 ? 0 : p[i - 1])) %
                MOD,
                  f[i + 1][j][k | 1][l ^ 1] =
                      (f[i + 1][j][k | 1][l ^ 1] +
                       1ll * f[i][j][k][l] * (j == 0 ? p[i] : p[i - 1])) %
                      MOD;
          if (dat[i + 1] != 0)
            f[i + 1][j][k][l] =
                (f[i + 1][j][k][l] +
                 1ll * f[i][j][k][l] * (k == 0 ? 0 : p[i - 1])) %
                MOD,
                  f[i + 1][j | 1][k][l ^ 1] =
                      (f[i + 1][j | 1][k][l ^ 1] +
                       1ll * f[i][j][k][l] * (k == 0 ? p[i] : p[i - 1])) %
                      MOD;
        }
  int ans = 0;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) Add(ans, f[n][i][j][opt]);
  printf("%d\n", ans);
  return 0;
}
