#include <bits/stdc++.h>
const int _ML = 228;
const char _inpf[] = "";
const char _outf[] = "";
#pragma GCC optimize("O3,no-stack-protector")
using namespace std;
const double PI = 3.14159265358979323846;
mt19937 rd(228);
template <class T, class U>
inline ostream &operator<<(ostream &, const pair<T, U> &);
template <class T, class U>
inline istream &operator>>(istream &, pair<T, U> &);
template <class T>
inline ostream &operator<<(ostream &, const vector<T> &);
template <class T>
inline istream &operator>>(istream &, vector<T> &);
template <class T>
inline ostream &operator<<(ostream &, const set<T> &);
template <class T>
inline ostream &operator<<(ostream &, const multiset<T> &);
template <class T>
inline ostream &operator<<(ostream &, const unordered_set<T> &);
template <class T>
inline ostream &operator<<(ostream &, const unordered_multiset<T> &);
template <class T, class U>
inline ostream &operator<<(ostream &, const map<T, U> &);
template <class T, class U>
inline ostream &operator<<(ostream &, const unordered_map<T, U> &);
const int N = 52;
const int M = 1000 * 1000 * 1000 + 7;
int dp[2][N][N][N];
int a[N];
int pww[N];
inline int pw2(int first) {
  if (first == -1) {
    return 1;
  }
  return pww[first];
}
inline int mul(int a, int b) { return (int)((long long)a * b % M); }
inline void addeq(int &a, int b) { a = (a + b) % M; }
inline void _main_function() {
  pww[0] = 1;
  for (int i = 1; i < N; ++i) {
    pww[i] = mul(pww[i - 1], 2);
  }
  int n, p;
  cin >> n >> p;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  dp[1][0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    int cur = (i & 1);
    int lst = (~i & 1);
    memset(dp[cur], 0, sizeof dp[cur]);
    for (int e = 0; e <= i; ++e) {
      for (int bo = 0; bo <= i; ++bo) {
        for (int wo = 0; wo <= i; ++wo) {
          if (dp[lst][e][bo][wo] == 0) {
            continue;
          }
          if (a[i] != 1) {
            int value = mul(pw2(e + bo), pw2(wo - 1));
            addeq(dp[cur][e][bo + 1][wo], mul(dp[lst][e][bo][wo], value));
            if (wo != 0) {
              addeq(dp[cur][e + 1][bo][wo], mul(dp[lst][e][bo][wo], value));
            }
          }
          if (a[i] != 0) {
            int value = mul(pw2(e + wo), pw2(bo - 1));
            if (bo != 0) {
              addeq(dp[cur][e + 1][bo][wo], mul(dp[lst][e][bo][wo], value));
            }
            addeq(dp[cur][e][bo][wo + 1], mul(dp[lst][e][bo][wo], value));
          }
        }
      }
    }
  }
  int cur = ((n - 1) & 1);
  int ans = 0;
  for (int e = 0; e <= n; ++e) {
    for (int bo = 0; bo <= n; ++bo) {
      for (int wo = 0; wo <= n; ++wo) {
        if (((bo + wo) & 1) == p) {
          addeq(ans, dp[cur][e][bo][wo]);
        }
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  if (_inpf[0] != '\0') assert(freopen(_inpf, "r", stdin) != nullptr);
  if (_outf[0] != '\0') assert(freopen(_outf, "w", stdout) != nullptr);
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << setprecision(20);
  _main_function();
}
template <class T, class U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second;
  return _out;
}
template <class T, class U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <class T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << *_v.begin();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <class T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <class T, class U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <class T, class U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
