#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int SIZE = 1 << 20;
char buf[SIZE + 10], *iS, *iT;
inline char Getc() {
  return iS == iT && (iT = (iS = buf) + fread(buf, 1, SIZE, stdin), iS == iT)
             ? EOF
             : *iS++;
}
template <class TT>
inline void Read(TT &x) {
  x = 0;
  register char cc = '\0';
  TT fff = 1;
  for (; cc < '0' || cc > '9'; cc = Getc())
    if (cc == '-') fff = -1;
  for (; cc >= '0' && cc <= '9'; cc = Getc())
    x = (x << 1) + (x << 3) + (cc & 15);
  x *= fff;
}
}  // namespace IO
using IO::Read;
const int N = 2e5 + 10, Mod = 1e9 + 7;
int n, fid, a[N], fpw[N + 10], f[N][2][2][2];
int main() {
  fpw[0] = 1;
  for (int i = 1; i <= N; ++i) fpw[i] = (long long)fpw[i - 1] * 2LL % Mod;
  Read(n), Read(fid);
  for (int i = 1; i <= n; ++i) Read(a[i]);
  if (a[1] != 1) f[1][1][1][0] = 1;
  if (a[1] != 0) f[1][1][0][1] = 1;
  for (int i = 2; i <= n; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k)
        for (int u = 0; u < 2; ++u) {
          if (!f[i - 1][j][k][u]) continue;
          if (a[i] != 1) {
            if (u) {
              f[i][j ^ 1][k | 1][u] =
                  (f[i][j ^ 1][k | 1][u] +
                   (long long)f[i - 1][j][k][u] * fpw[i - 2]) %
                  Mod;
              f[i][j][k][u] =
                  (f[i][j][k][u] + (long long)f[i - 1][j][k][u] * fpw[i - 2]) %
                  Mod;
            } else
              f[i][j ^ 1][k | 1][u] =
                  (f[i][j ^ 1][k | 1][u] +
                   (long long)f[i - 1][j][k][u] * fpw[i - 1]) %
                  Mod;
          }
          if (a[i] != 0) {
            if (k) {
              f[i][j ^ 1][k][u | 1] =
                  (f[i][j ^ 1][k][u | 1] +
                   (long long)f[i - 1][j][k][u] * fpw[i - 2]) %
                  Mod;
              f[i][j][k][u] =
                  (f[i][j][k][u] + (long long)f[i - 1][j][k][u] * fpw[i - 2]) %
                  Mod;
            } else
              f[i][j ^ 1][k][u | 1] =
                  (f[i][j ^ 1][k][u | 1] +
                   (long long)f[i - 1][j][k][u] * fpw[i - 1]) %
                  Mod;
          }
        }
  int fans = 0;
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j) fans = (fans + f[n][fid][i][j]) % Mod;
  printf("%d\n", fans);
  return 0;
}
