#include <bits/stdc++.h>
using namespace std;
long long f[54][2][2][2], n, p, col[101], two[101];
int main() {
  cin >> n >> p;
  two[0] = 1;
  for (int i = 1; i <= n; i++)
    cin >> col[i], two[i] = two[i - 1] * 2 % 1000000007;
  f[0][0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int len = 0; len <= 1; len++) {
      for (int jb = 0; jb <= 1; jb++) {
        for (int jw = 0; jw <= 1; jw++) {
          if (!f[i - 1][len][jb][jw]) continue;
          long long las = f[i - 1][len][jb][jw];
          if (col[i] != 1) {
            if (jw) {
              f[i][len ^ 1][1 | jb][1] =
                  (f[i][len ^ 1][1 | jb][1] + las * two[i - 2] % 1000000007) %
                  1000000007;
              f[i][len][jb][1] =
                  (f[i][len][jb][1] + las * two[i - 2] % 1000000007) %
                  1000000007;
            } else {
              f[i][len ^ 1][1][0] =
                  (f[i][len ^ 1][1][0] + las * two[i - 1]) % 1000000007;
            }
          }
          if (col[i] != 0) {
            if (jb) {
              f[i][len ^ 1][1][1 | jw] =
                  (f[i][len ^ 1][1][1 | jw] + las * two[i - 2] % 1000000007) %
                  1000000007;
              f[i][len][1][jw] =
                  (f[i][len][1][jw] + las * two[i - 2] % 1000000007) %
                  1000000007;
            } else {
              f[i][len ^ 1][0][1] =
                  (f[i][len ^ 1][0][1] + las * two[i - 1]) % 1000000007;
            }
          }
        }
      }
    }
  }
  cout << (f[n][p][0][0] + f[n][p][1][0] + f[n][p][0][1] + f[n][p][1][1]) %
              1000000007;
  return 0;
}
