#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int kcz = 1000000007;
long long f[2][2][2][2], p2[maxn];
int cur;
int main() {
  int n, p, i, c, j, k, l;
  long long ans;
  scanf("%d%d", &n, &p);
  for (p2[0] = 1, i = 1; i <= n; i++) p2[i] = (p2[i - 1] << 1) % kcz;
  cur = 0, memset(f[cur], 0, sizeof(f[cur])), f[cur][0][0][0] = 1;
  for (i = 0; i < n; i++) {
    cur ^= 1, memset(f[cur], 0, sizeof(f[cur]));
    scanf("%d", &c);
    for (j = 0; j <= 1; j++)
      for (k = 0; k <= 1; k++)
        for (l = 0; l <= 1; l++) {
          if (c != 1) {
            (f[cur][1][k][l ^ 1] += f[cur ^ 1][j][k][l] * p2[k ? i - 1 : i]) %=
                kcz;
            if (k) (f[cur][j][k][l] += f[cur ^ 1][j][k][l] * p2[i - 1]) %= kcz;
          }
          if (c != 0) {
            (f[cur][j][1][l ^ 1] += f[cur ^ 1][j][k][l] * p2[j ? i - 1 : i]) %=
                kcz;
            if (j) (f[cur][j][k][l] += f[cur ^ 1][j][k][l] * p2[i - 1]) %= kcz;
          }
        }
  }
  ans = 0;
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++) ans += f[cur][i][j][p];
  printf("%lld\n", ans %= kcz);
  return 0;
}
