#include <bits/stdc++.h>
using namespace std;
const int maxn = 50 + 2;
const int maxm = 2 + 2;
const int mod = 1e9 + 7;
int n, p;
int a[maxn], _2[maxn];
int dp[maxn][maxm][maxm][maxm];
void DP() {
  dp[0][0][0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 1; j++)
      for (int ob = 0; ob <= 1; ob++)
        for (int ow = 0; ow <= 1; ow++) {
          int tmp = dp[i - 1][j][ob][ow];
          if (a[i] != 0) {
            if (ob) {
              dp[i][j][ob][ow] =
                  (dp[i][j][ob][ow] + 1LL * tmp * _2[i - 2]) % mod;
              dp[i][j ^ 1][ob][ow | 1] =
                  (dp[i][j ^ 1][ob][ow | 1] + 1LL * tmp * _2[i - 2]) % mod;
            } else
              dp[i][j ^ 1][ob][ow | 1] =
                  (dp[i][j ^ 1][ob][ow | 1] + 1LL * tmp * _2[i - 1]) % mod;
          }
          if (a[i] != 1) {
            if (ow) {
              dp[i][j][ob][ow] =
                  (dp[i][j][ob][ow] + 1LL * tmp * _2[i - 2]) % mod;
              dp[i][j ^ 1][ob | 1][ow] =
                  (dp[i][j ^ 1][ob | 1][ow] + 1LL * tmp * _2[i - 2]) % mod;
            } else
              dp[i][j ^ 1][ob | 1][ow] =
                  (dp[i][j ^ 1][ob | 1][ow] + 1LL * tmp * _2[i - 1]) % mod;
          }
        }
}
void init() {
  _2[0] = 1;
  for (int i = 1; i <= n; i++) _2[i] = (_2[i - 1] << 1) % mod;
}
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  init();
  DP();
  int ans = 0;
  for (int ob = 0; ob <= 1; ob++)
    for (int ow = 0; ow <= 1; ow++) ans = (ans + dp[n][p][ob][ow]) % mod;
  printf("%d", ans);
  return 0;
}
