#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, g[200010];
long long f[200010][2][2][2], ba[200010], ans = 0, p;
int main() {
  cin >> n >> p;
  for (int i = 1; i <= n; i++) scanf("%d", &g[i]);
  ba[0] = 1;
  for (int i = 1; i <= n; i++) ba[i] = ba[i - 1] * 2 % mod;
  f[0][0][0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++)
        for (int h = 0; h < 2; h++) {
          if (!f[i - 1][j][k][h]) continue;
          long long tt = f[i - 1][j][k][h];
          if (g[i] != 0) {
            if (!j)
              f[i][0][1][h ^ 1] =
                  (f[i][0][1][h ^ 1] + tt * ba[i - 1] % mod) % mod;
            else
              f[i][1][1][h ^ 1] =
                  (f[i][1][1][h ^ 1] + tt * ba[i - 2] % mod) % mod,
                             f[i][1][k][h] =
                                 (f[i][1][k][h] + tt * ba[i - 2] % mod) % mod;
          }
          if (g[i] != 1) {
            if (!k)
              f[i][1][0][h ^ 1] =
                  (f[i][1][0][h ^ 1] + tt * ba[i - 1] % mod) % mod;
            else
              f[i][1][1][h ^ 1] =
                  (f[i][1][1][h ^ 1] + tt * ba[i - 2] % mod) % mod,
                             f[i][j][1][h] =
                                 (f[i][j][1][h] + tt * ba[i - 2] % mod) % mod;
          }
        }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) ans = (ans + f[n][i][j][p]) % mod;
  cout << ans << endl;
  return 0;
}
