#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, p, d, ans, a[55], p2[55], f[55][2][2][2];
signed main() {
  scanf("%lld%lld", &n, &p);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  f[0][0][0][0] = 1;
  p2[0] = 1;
  for (long long i = 1; i <= n; i++) p2[i] = p2[i - 1] * 2 % mod;
  for (long long i = 1; i <= n; i++)
    for (long long b = 0; b <= 1; b++)
      for (long long w = 0; w <= 1; w++)
        for (long long a2 = 0; a2 <= 1; a2++) {
          d = f[i - 1][b][w][a2];
          if (a[i] != 0) {
            if ((!b) || i == 1)
              f[i][b][w | 1][a2 ^ 1] =
                  (f[i][b][w | 1][a2 ^ 1] + d * p2[i - 1] % mod) % mod;
            else {
              f[i][b][w][a2] = (f[i][b][w][a2] + d * p2[i - 2] % mod) % mod;
              f[i][b][w | 1][a2 ^ 1] =
                  (f[i][b][w | 1][a2 ^ 1] + d * p2[i - 2] % mod) % mod;
            }
          }
          if (a[i] != 1) {
            if ((!w) || i == 1)
              f[i][b | 1][w][a2 ^ 1] =
                  (f[i][b | 1][w][a2 ^ 1] + d * p2[i - 1] % mod) % mod;
            else {
              f[i][b][w][a2] = (f[i][b][w][a2] + d * p2[i - 2] % mod) % mod;
              f[i][b | 1][w][a2 ^ 1] =
                  (f[i][b | 1][w][a2 ^ 1] + d * p2[i - 2] % mod) % mod;
            }
          }
        }
  for (long long i = 0; i <= 1; i++)
    for (long long j = 0; j <= 1; j++) ans = (ans + f[n][i][j][p]) % mod;
  printf("%lld\n", ans);
  return 0;
}
