#include <bits/stdc++.h>
using namespace std;
int dp[55][2][2][2], a[55], pow2[55];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  pow2[0] = 1;
  for (int i = 1; i <= n; i++) {
    pow2[i] = 1ll * 2 * pow2[i - 1] % (int)(1e9 + 7);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  dp[0][0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 1; j++) {
      if (a[i] != 1) {
        if (i > 1)
          dp[i][j][0][1] +=
              (long long)(dp[i - 1][j][0][1]) * pow2[i - 2] % (int)(1e9 + 7);
        dp[i][j][1][0] +=
            (long long)(dp[i - 1][j ^ 1][1][0] + dp[i - 1][j ^ 1][0][0]) *
            pow2[i - 1] % (int)(1e9 + 7);
        if (i > 1)
          dp[i][j][1][1] +=
              (long long)dp[i - 1][j][1][1] * pow2[i - 2] % (int)(1e9 + 7);
        dp[i][j][1][1] %= (int)(1e9 + 7);
        if (i > 1)
          dp[i][j][1][1] +=
              (long long)(dp[i - 1][j ^ 1][0][1] + dp[i - 1][j ^ 1][1][1]) *
              pow2[i - 2] % (int)(1e9 + 7);
      }
      dp[i][j][0][1] %= (int)(1e9 + 7);
      dp[i][j][1][0] %= (int)(1e9 + 7);
      dp[i][j][1][1] %= (int)(1e9 + 7);
      if (a[i] != 0) {
        if (i > 1)
          dp[i][j][1][0] +=
              (long long)(dp[i - 1][j][1][0]) * pow2[i - 2] % (int)(1e9 + 7);
        dp[i][j][0][1] +=
            (long long)(dp[i - 1][j ^ 1][0][1] + dp[i - 1][j ^ 1][0][0]) *
            pow2[i - 1] % (int)(1e9 + 7);
        if (i > 1)
          dp[i][j][1][1] +=
              (long long)dp[i - 1][j][1][1] * pow2[i - 2] % (int)(1e9 + 7);
        dp[i][j][1][1] %= (int)(1e9 + 7);
        if (i > 1)
          dp[i][j][1][1] +=
              (long long)(dp[i - 1][j ^ 1][1][0] + dp[i - 1][j ^ 1][1][1]) *
              pow2[i - 2] % (int)(1e9 + 7);
      }
      dp[i][j][0][1] %= (int)(1e9 + 7);
      dp[i][j][1][0] %= (int)(1e9 + 7);
      dp[i][j][1][1] %= (int)(1e9 + 7);
    }
  }
  cout << ((long long)dp[n][m][1][1] + dp[n][m][1][0] + dp[n][m][0][1]) %
              (int)(1e9 + 7);
  return 0;
}
