#include <bits/stdc++.h>
using namespace std;
long long mo = 1000000007;
long long n, p, a[123456], ans;
long long f[123456][3][3][3], mul[123456];
int main() {
  scanf("%lld%lld", &n, &p);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  mul[0] = 1;
  for (long long i = 1; i <= n; i++) {
    mul[i] = (mul[i - 1] * 2) % mo;
  }
  f[0][0][0][0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long num = 0; num <= 1; num++)
      for (long long bla = 0; bla <= 1; bla++)
        for (long long whi = 0; whi <= 1; whi++) {
          long long x = f[i - 1][num][bla][whi];
          if (a[i] == 1 || a[i] == -1) {
            if (bla == 1) {
              f[i][num][bla][whi] =
                  (f[i][num][bla][whi] + (mul[i - 2] * x) % mo) % mo;
              f[i][1 - num][bla][1] =
                  (f[i][1 - num][bla][1] + (mul[i - 2] * x) % mo) % mo;
            } else
              f[i][1 - num][bla][1] =
                  (f[i][1 - num][bla][1] + (mul[i - 1] * x) % mo) % mo;
          }
          if (a[i] == 0 || a[i] == -1) {
            if (whi == 1) {
              f[i][num][bla][whi] =
                  (f[i][num][bla][whi] + (mul[i - 2] * x) % mo) % mo;
              f[i][1 - num][1][whi] =
                  (f[i][1 - num][1][whi] + (mul[i - 2] * x) % mo) % mo;
            } else
              f[i][1 - num][1][whi] =
                  (f[i][1 - num][1][whi] + (mul[i - 1] * x) % mo) % mo;
          }
        }
  for (long long bla = 0; bla <= 1; bla++)
    for (long long whi = 0; whi <= 1; whi++)
      ans = (ans + f[n][p][bla][whi]) % mo;
  printf("%lld", ans);
}
