#include <bits/stdc++.h>   template <class T>   void cxk(T& a, T b) {     a = a > b ? a : b;   }   template <class T>   void cnk(T& a, T b) {     a = a < b ? a : b;   }   long long gi() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? x : -x;   }   int col[200010], f[200010][2][2][2], p2[400010];   void inc(int& x, int y) {     x = x + y >= 1000000007 ? x + y - 1000000007 : x + y;   }   int main() {     int n = gi(), p = gi();     for (int i = 1; i <= n; ++i) col[i] = gi();     p2[0] = 1;     for (int i = 1; i <= n + n; ++i) p2[i] = 2 * p2[i - 1] % 1000000007;     f[1][0][0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j < 2; ++j)         for (int k = 0; k < 2; ++k)           for (int l = 0; l < 2; ++l)             if (f[i][j][k][l]) {               if (col[i] != 1) {                 inc(f[i + 1][1][k][!l],                     1ll * p2[i - 1 - !!k] * f[i][j][k][l] % 1000000007);                 if (k)                   inc(f[i + 1][j][k][l],                       1ll * p2[i - 2] * f[i][j][k][l] % 1000000007);               }               if (col[i] != 0) {                 inc(f[i + 1][j][1][!l],                     1ll * p2[i - 1 - !!j] * f[i][j][k][l] % 1000000007);                 if (j)                   inc(f[i + 1][j][k][l],                       1ll * p2[i - 2] * f[i][j][k][l] % 1000000007);               }             }     int ans = 0;     for (int i = 0; i < 2; ++i)       for (int j = 0; j < 2; ++j) inc(ans, f[n + 1][i][j][p]);     printf( %d n , ans);     return 0;   }   