#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     int count(vector<int>& pieces, int p) {       int n = pieces.size();       preprocess(n);       vector<vector<vector<int>>> cur(           n + 1, vector<vector<int>>(n + 1, vector<int>(n + 1, 0)));       vector<vector<vector<int>>> nxt(           n + 1, vector<vector<int>>(n + 1, vector<int>(n + 1, 0)));       cur[0][0][0] = 1;       for (int i = 0; i < n; ++i) {         vector<int> cv;         if (pieces[i] == -1) {           cv.push_back(0);           cv.push_back(1);         } else {           cv.push_back(pieces[i]);         }         for (auto& vv : nxt) {           for (auto& v : vv) {             fill(v.begin(), v.end(), 0);           }         }         for (int j = 0; j <= i; ++j) {           for (int k = 0; k <= j; ++k) {             for (int l = 0; l <= i - j; ++l) {               if (cur[j][k][l] == 0) {                 continue;               }               for (auto c : cv) {                 if (c == 0) {                   int nj = j + 1;                   nxt[nj][k + 1][l] =                       add(nxt[nj][k + 1][l],                           multiply(cur[j][k][l],                                    multiply(1LL << j, multiply(1LL << (i - j - l),                                                                csums[l][0]))));                   nxt[nj][k][l] =                       add(nxt[nj][k][l],                           multiply(cur[j][k][l],                                    multiply(1LL << j, multiply(1LL << (i - j - l),                                                                csums[l][1]))));                 } else {                   int nj = j;                   nxt[nj][k][l + 1] = add(                       nxt[nj][k][l + 1],                       multiply(cur[j][k][l],                                multiply(1LL << (i - j),                                         multiply(1LL << (j - k), csums[k][0]))));                   nxt[nj][k][l] = add(                       nxt[nj][k][l],                       multiply(cur[j][k][l],                                multiply(1LL << (i - j),                                         multiply(1LL << (j - k), csums[k][1]))));                 }               }             }           }         }         cur.swap(nxt);       }       long long res = 0;       for (int i = 0; i <= n; ++i) {         for (int j = 0; j <= i; ++j) {           for (int k = 0; k <= n - i; ++k) {             if ((j + k) % 2 == p) {               res = add(res, cur[i][j][k]);             }           }         }       }       return res;     }       private:     const static int M = 1e9 + 7;     vector<int> fv;     vector<int> ifv;     vector<vector<int>> cs;     vector<vector<int>> csums;     long long add(long long a, long long b) {       long long res = (a + b) % M;       return res;     }     long long multiply(long long a, long long b) { return (a * b) % M; }     long long pow(long long x, long long e) {       long long res = 1;       while (e > 0) {         if (e & 1) {           res = multiply(res, x);         }         x = multiply(x, x);         e >>= 1;       }       return res;     }     void preprocess(int n) {       fv.clear();       fv.resize(n + 1);       ifv.clear();       ifv.resize(n + 1);       cs.clear();       cs.resize(n + 1);       csums.clear();       csums.resize(n + 1);       for (auto& v : csums) {         v.resize(2);         fill(v.begin(), v.end(), 0);       }       fv[0] = 1;       for (int i = 1; i <= n; ++i) {         fv[i] = multiply(fv[i - 1], i);       }       ifv[0] = 1;       ifv[n] = pow(fv[n], M - 2);       for (int i = n - 1; i >= 1; --i) {         ifv[i] = multiply(ifv[i + 1], i + 1);       }       for (int i = 1; i <= n; ++i) {         cs[i].resize(i + 1);         for (int j = 0; j <= i; ++j) {           cs[i][j] = multiply(multiply(fv[i], ifv[j]), ifv[i - j]);         }       }       csums[0][0] = 1;       for (int i = 1; i <= n; ++i) {         for (int j = 0; j <= i; ++j) {           if (j % 2) {             csums[i][1] = add(csums[i][1], cs[i][j]);           } else {             csums[i][0] = add(csums[i][0], cs[i][j]);           }         }       }     }   };   int main(int argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     int p;     cin >> n >> p;     vector<int> nums(n);     for (int i = 0; i < n; ++i) {       cin >> nums[i];     }     Solution sol;     cout << sol.count(nums, p) << endl;     return 0;   }