#include <bits/stdc++.h>
using namespace std;
int read() {
  int sum = 0, f = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') ch = getchar(), f = -1;
  while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
  return sum * f;
}
int val[100010], n, p;
int f[100010][2][2][2];
const int mod = 1e9 + 7;
int poww[100010];
void pre() {
  poww[0] = 1;
  for (int i = 1; i <= 100000; i++) poww[i] = 1ll * poww[i - 1] * 2 % mod;
}
void fix(int &a, int b) {
  a = (a + b) % mod;
  a += mod;
  a %= mod;
}
int main() {
  pre();
  n = read(), p = read();
  for (int i = 1; i <= n; i++) val[i] = read();
  f[0][0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    if (!val[i + 1]) {
      for (int j = 0; j <= 1; j++)
        for (int k = 0; k <= 1; k++)
          for (int l = 0; l <= 1; l++)
            if (f[i][j][k][l]) {
              if (l) {
                fix(f[i + 1][j ^ 1][1][l],
                    1ll * f[i][j][k][l] * poww[i - 1] % mod);
                fix(f[i + 1][j][k][l], 1ll * f[i][j][k][l] * poww[i - 1] % mod);
              } else
                fix(f[i + 1][j ^ 1][1][l], 1ll * f[i][j][k][l] * poww[i] % mod);
            }
    } else if (val[i + 1] == 1) {
      for (int j = 0; j <= 1; j++)
        for (int k = 0; k <= 1; k++)
          for (int l = 0; l <= 1; l++)
            if (f[i][j][k][l]) {
              if (k) {
                fix(f[i + 1][j ^ 1][k][1],
                    1ll * f[i][j][k][l] * poww[i - 1] % mod);
                fix(f[i + 1][j][k][l], 1ll * f[i][j][k][l] * poww[i - 1] % mod);
              } else
                fix(f[i + 1][j ^ 1][k][1], 1ll * f[i][j][k][l] * poww[i] % mod);
            }
    } else {
      for (int j = 0; j <= 1; j++)
        for (int k = 0; k <= 1; k++)
          for (int l = 0; l <= 1; l++)
            if (f[i][j][k][l]) {
              if (l) {
                fix(f[i + 1][j ^ 1][1][l],
                    1ll * f[i][j][k][l] * poww[i - 1] % mod);
                fix(f[i + 1][j][k][l], 1ll * f[i][j][k][l] * poww[i - 1] % mod);
              } else
                fix(f[i + 1][j ^ 1][1][l], 1ll * f[i][j][k][l] * poww[i] % mod);
            }
      for (int j = 0; j <= 1; j++)
        for (int k = 0; k <= 1; k++)
          for (int l = 0; l <= 1; l++)
            if (f[i][j][k][l]) {
              if (k) {
                fix(f[i + 1][j ^ 1][k][1],
                    1ll * f[i][j][k][l] * poww[i - 1] % mod);
                fix(f[i + 1][j][k][l], 1ll * f[i][j][k][l] * poww[i - 1] % mod);
              } else
                fix(f[i + 1][j ^ 1][k][1], 1ll * f[i][j][k][l] * poww[i] % mod);
            }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 1; i++)
    for (int j = 0; j <= 1; j++) fix(ans, f[n][p][i][j]);
  cout << ans;
  return 0;
}
