Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.The paper is divided into $$$n$$$ pieces enumerated from $$$1$$$ to $$$n$$$. Shiro has painted some pieces with some color. Specifically, the $$$i$$$-th piece has color $$$c_{i}$$$ where $$$c_{i} = 0$$$ defines black color, $$$c_{i} = 1$$$ defines white color and $$$c_{i} = -1$$$ means that the piece hasn't been colored yet.The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($$$0$$$ or $$$1$$$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $$$[1 \to 0 \to 1 \to 0]$$$, $$$[0 \to 1 \to 0 \to 1]$$$, $$$[1]$$$, $$$[0]$$$ are valid paths and will be counted. You can only travel from piece $$$x$$$ to piece $$$y$$$ if and only if there is an arrow from $$$x$$$ to $$$y$$$.But Kuro is not fun yet. He loves parity. Let's call his favorite parity $$$p$$$ where $$$p = 0$$$ stands for "even" and $$$p = 1$$$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $$$p$$$.It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $$$10^{9} + 7$$$.

The first line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \leq n \leq 50$$$, $$$0 \leq p \leq 1$$$) — the number of pieces and Kuro's wanted parity. The second line contains $$$n$$$ integers $$$c_{1}, c_{2}, ..., c_{n}$$$ ($$$-1 \leq c_{i} \leq 1$$$) — the colors of the pieces.

Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $$$p$$$.

NoteIn the first example, there are $$$6$$$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $$$3, 3, 5$$$ for the first row and $$$5, 3, 3$$$ for the second row, both from left to right.

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int p=scan.nextInt();
		int[] col=new int[n];
		for(int i=0;i<n;i++){
			col[i]=scan.nextInt();
		}
		Paths paths=new Paths();
		paths.calc(n,p,col);
		System.out.println(paths.f(0,0,0));
	}
}

class Paths{
	long MOD=1000000007;
	long[] pow2=new long[51];
	int[] col=new int[51];
	long[][][] dp=new long[51][51][51];
	int n;
	int P;

	void calc(int N,int parity,int[] C){
		n=N;
		P=parity;
		for(int i=0;i<n;i++){
			col[i]=C[i];
		}
		pow2[0]=1;
		for(int i=1;i<=50;i++){
			pow2[i]=(2*pow2[i-1])%MOD;
		}
		for(int i=0;i<=50;i++){
			for(int j=0;j<=50;j++){
				for(int k=0;k<=50;k++){
					dp[i][j][k]=-1;
				}
			}
		}
	}

	long f(int i,int ob,int ow){
		int p=ob+ow;
		if(i==n){
			if(p%2==P){return 1;}
			else{return 0;}
		}
		long res=dp[i][ob][ow];
		if(res!=-1){return res;}
		res=0;
		if(col[i]==1 || col[i]==-1){ //white
			long even=0;
			long odd=0;
			if(ob>0){
				even=pow2[ob-1];
				odd=pow2[ob-1];
			}
			else{
				even=1;
				odd=0;
			}
			long u=even*f(i+1,ob,ow+1)+odd*f(i+1,ob,ow);
			u%=MOD;
			res+=pow2[i-ob]*u;
			res%=MOD;
		}
		if(col[i]==0 || col[i]==-1){ //black
			long even=0;
			long odd=0;
			if(ow>0){
				even=pow2[ow-1];
				odd=pow2[ow-1];
			}
			else{
				even=1;
				odd=0;
			}
			long u=even*f(i+1,ob+1,ow)+odd*f(i+1,ob,ow);
			u%=MOD;
			res+=pow2[i-ow]*u;
			res%=MOD;
		}
		dp[i][ob][ow]=res;
		return res;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class KuroAndTopologicalParity {

    int MOD = (int) 1e9 + 7;
    int N = 55;

    long[] p2 = new long[N];
    long[][] c = new long[N][N];
    long[][] cs = new long[N][2];

    long[][][][] dp = new long[N][N][N][N];

    {
        p2[0] = 1;
        for (int i = 1; i < N; i++) p2[i] = p2[i - 1] * 2 % MOD;

        for (int i = 0; i < N; i++) {
            c[i][0] = 1;
            for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                cs[i][j & 1] = (cs[i][j & 1] + c[i][j]) % MOD;
            }
        }
    }

    void solve() {
        int n = in.nextInt(), p = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();

        long ans = 0;
        dp[0][0][0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int ob = 0; ob <= i + 1; ob++) {
                for (int eb = 0; ob + eb <= i + 1; eb++) {
                    for (int ow = 0; ob + eb + ow <= i + 1; ow++) {
                        int ew = (i + 1) - (ob + eb + ow);
                        calc(a[i], ob, eb, ow, ew);
                        if (i + 1 == n && (ob + ow) % 2 == p) {
                            ans = (ans + dp[ob][eb][ow][ew]) % MOD;
                        }
                    }
                }
            }
        }
        out.println(ans);
    }

    void calc(int color, int ob, int eb, int ow, int ew) {
        if (color != 0 && ew > 0) {
            dp[ob][eb][ow][ew] += dp[ob][eb][ow][ew - 1] * p2[ow + ew + eb - 1] % MOD * cs[ob][1] % MOD;
        }
        if (color != 0 && ow > 0) {
            dp[ob][eb][ow][ew] += dp[ob][eb][ow - 1][ew] * p2[ow + ew + eb - 1] % MOD * cs[ob][0] % MOD;
        }
        if (color != 1 && eb > 0) {
            dp[ob][eb][ow][ew] += dp[ob][eb - 1][ow][ew] * p2[ob + eb + ew - 1] % MOD * cs[ow][1] % MOD;
        }
        if (color != 1 && ob > 0) {
            dp[ob][eb][ow][ew] += dp[ob - 1][eb][ow][ew] * p2[ob + eb + ew - 1] % MOD * cs[ow][0] % MOD;
        }
        dp[ob][eb][ow][ew] %= MOD;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new KuroAndTopologicalParity().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class KuroAndTopologicalParity2 {

    int MOD = (int) 1e9 + 7;
    int N = 55;

    long[] p2 = new long[N];
    long[][] c = new long[N][N];
    long[][] cs = new long[N][2];

    long[][][] dp = new long[N][N][N];

    {
        p2[0] = 1;
        for (int i = 1; i < N; i++) p2[i] = p2[i - 1] * 2 % MOD;

        for (int i = 0; i < N; i++) {
            c[i][0] = 1;
            for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                cs[i][j & 1] = (cs[i][j & 1] + c[i][j]) % MOD;
            }
        }
    }

    void solve() {
        int n = in.nextInt(), p = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();

        long ans = 0;
        dp[0][0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int ob = 0; ob <= i + 1; ob++) {
                for (int ow = 0; ob + ow <= i + 1; ow++) {
                    if (a[i] != 0 && i - ob >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow] * p2[i - ob]%MOD * cs[ob][1]%MOD ;
                    if (a[i] != 0 && ow - 1 >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow - 1] * p2[i - ob]%MOD  * cs[ob][0]%MOD ;
                    if (a[i] != 1 && i - ow >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow] * p2[i - ow]%MOD  * cs[ow][1]%MOD ;
                    if (a[i] != 1 && ob - 1 >= 0) dp[i + 1][ob][ow] += dp[i][ob - 1][ow] * p2[i - ow]%MOD  * cs[ow][0]%MOD ;
                    dp[i + 1][ob][ow] %= MOD;
                    if (i + 1 == n && ((ob + ow) & 1) == p) ans = (ans + dp[i + 1][ob][ow])%MOD;
                }
            }
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new KuroAndTopologicalParity2().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

import java.io.*;
import java.util.*;

public class Codeforces979E {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int p = Integer.parseInt(st.nextToken());
		int[] c = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++) {
			c[i] = Integer.parseInt(st.nextToken());
		}

		//list of powers of 2 until 2^{n^2}, mod 1000000007
		int[] twopower = new int[n*n+1];
		twopower[0] = 1;
		for (int i = 1; i <= n*n; i++) {
			twopower[i] = (2*twopower[i-1])%1000000007;
		}

		//Pascal's triangle until n choose k, mod 1000000007
		int[][] pascal = new int[n+1][n+1];
		for (int i = 0; i <= n; i++) {
			pascal[i][0] = 1;
			pascal[0][i] = 1;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				pascal[i][j] = (pascal[i][j-1]+pascal[i-1][j])%1000000007;
			}
		}

		//dp[x][y][z] means the last x have all arrows intact
		//and there are y 0's and z 1's at the start with no
		//arrows going between them.
		//we only care when 0 <= x+y+z <= n.
		//answer is dp[n][0][0].
		int[][][] dp = new int[n+1][n+1][n+1];
		//base case of x = 0
		for (int y = 0; y <= n; y++) {
			for (int z = 0; z <= (n-y); z++) {
				if (p == (y+z)%2) {
					dp[0][y][z] = 1;
				}
			}
		}

		for (int x = 1; x <= n; x++) {
			for (int y = 0; y <= (n-x); y++) {
				for (int z = 0; z <= (n-x-y); z++) {
					if (c[n-x] != 1) {
						int evenmultiple;
						int oddmultiple;
						if (z == 0) {
							evenmultiple = 1;
							oddmultiple = 0;
						}
						else {
							evenmultiple = twopower[z-1];
							oddmultiple = twopower[z-1];
						}
						long evenk = (long) evenmultiple * (long) dp[x-1][y+1][z];
						evenk %= 1000000007;
						long oddk = (long) oddmultiple * (long) dp[x-1][y][z];
						oddk %= 1000000007;
						oddk *= (long) twopower[x-1];
						oddk %= 1000000007;
						long totalk = evenk+oddk;
						totalk *= twopower[y];
						totalk %= 1000000007;
						dp[x][y][z] += (int) totalk;
					}
					if (c[n-x] != 0) {
						int evenmultiple;
						int oddmultiple;
						if (y == 0) {
							evenmultiple = 1;
							oddmultiple = 0;
						}
						else {
							evenmultiple = twopower[y-1];
							oddmultiple = twopower[y-1];
						}
						long evenk = (long) evenmultiple * (long) dp[x-1][y][z+1];
						evenk %= 1000000007;
						long oddk = (long) oddmultiple * (long) dp[x-1][y][z];
						oddk %= 1000000007;
						oddk *= (long) twopower[x-1];
						oddk %= 1000000007;
						long totalk = evenk+oddk;
						totalk *= twopower[z];
						totalk %= 1000000007;
						dp[x][y][z] += (int) totalk;
					}
					dp[x][y][z] %= 1000000007;
				}
			}
		}

		pw.println(dp[n][0][0]);

		pw.close();
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            EKuroAndTopologicalParity solver = new EKuroAndTopologicalParity();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class EKuroAndTopologicalParity {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int p = in.readInt();

            Modular mod = new Modular(1e9 + 7);
            CachedPow pow = new CachedPow(2, n, mod);

            int[][][][] dp = new int[n + 1][2][2][2];
            dp[0][0][0][0] = 1;

            for (int i = 1; i <= n; i++) {
                int c = in.readInt();

                for (int j = 0; j < 2; j++) {
                    for (int k = 0; k < 2; k++) {
                        for (int t = 0; t < 2; t++) {
                            int cnt = i - 2 >= 0 ? pow.pow(i - 2) : 1;
                            if (c != 1) {
                                if (t == 1) {
                                    //pick odd
                                    dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(dp[i - 1][j][k][t], cnt));
                                    if (k == 1) {
                                        //pick even
                                        dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][1 - j][1][t], dp[i - 1][1 - j][0][t]), cnt));
                                    }
                                } else {
                                    if (k == 1) {
                                        dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][1 - j][0][t], dp[i - 1][1 - j][1][t]), pow.pow(i - 1)));
                                    }
                                }
                            }
                            if (c != 0) {
                                //pick odd
                                if (k == 1) {
                                    dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(dp[i - 1][j][k][t], cnt));
                                    if (t == 1) {
                                        //pick even
                                        dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][1 - j][k][1], dp[i - 1][1 - j][k][0]), cnt));
                                    }
                                } else {
                                    if (t == 1) {
                                        //pick even
                                        dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][1 - j][k][1], dp[i - 1][1 - j][k][0]), pow.pow(i - 1)));
                                    }
                                }

                            }
                        }
                    }
                }
            }

            int ans = 0;
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    ans = mod.plus(dp[n][p][i][j], ans);
                }
            }

            out.println(ans);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(int c) {
            cache.append(c).append('\n');
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public int valueOf(int x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return x;
        }

        public int valueOf(long x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return (int) x;
        }

        public int mul(int x, int y) {
            return valueOf((long) x * y);
        }

        public int plus(int x, int y) {
            return valueOf(x + y);
        }

        public Modular getModularForPowerComputation() {
            return new Modular(m - 1);
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static long round(double x) {
            if (x >= 0) {
                return (long) (x + 0.5);
            } else {
                return (long) (x - 0.5);
            }
        }

    }

    static class CachedPow {
        private int[] first;
        private int[] second;
        private Modular mod;
        private Modular powMod;

        public CachedPow(int x, Modular mod) {
            this(x, mod.getMod(), mod);
        }

        public CachedPow(int x, int maxExp, Modular mod) {
            this.mod = mod;
            this.powMod = mod.getModularForPowerComputation();
            int k = Math.max(1, (int) DigitUtils.round(Math.sqrt(maxExp)));
            first = new int[k];
            second = new int[maxExp / k + 1];
            first[0] = 1;
            for (int i = 1; i < k; i++) {
                first[i] = mod.mul(x, first[i - 1]);
            }
            second[0] = 1;
            int step = mod.mul(x, first[k - 1]);
            for (int i = 1; i < second.length; i++) {
                second[i] = mod.mul(second[i - 1], step);
            }
        }

        public int pow(int exp) {
            return mod.mul(first[exp % first.length], second[exp / first.length]);
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            EKuroAndTopologicalParity solver = new EKuroAndTopologicalParity();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class EKuroAndTopologicalParity {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int p = in.readInt();
            int[] c = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                c[i] = in.readInt();
            }

            Modular mod = new Modular(1e9 + 7);
            Composite comp = new Composite(n, mod);
            CachedPow pow = new CachedPow(2, mod);
            int[] pow2 = new int[n + 1];
            int[] compEven = new int[n + 1];
            int[] compOdd = new int[n + 1];
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= n; j += 2) {
                    compEven[i] = mod.plus(compEven[i], comp.composite(i, j));
                }
            }
            for (int i = 0; i <= n; i++) {
                for (int j = 1; j <= n; j += 2) {
                    compOdd[i] = mod.plus(compOdd[i], comp.composite(i, j));
                }
            }
            for (int i = 0; i <= n; i++) {
                pow2[i] = pow.pow(i);
            }

            int[][][][] last = new int[n + 1][n + 1][n + 1][2];
            int[][][][] next = new int[n + 1][n + 1][n + 1][2];

            last[0][0][0][0] = 1;
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j <= n; j++) {
                    for (int k = 0; k <= n; k++) {
                        for (int t = j; t + k <= i; t++) {
                            for (int parity = 0; parity < 2; parity++) {
                                next[j][k][t][parity] = 0;
                                if (c[i] != 1 && t > 0) {
                                    //it's 0 now

                                    //pick even and it's odd
                                    if (j > 0) {
                                        next[j][k][t][parity] = mod.plus(next[j][k][t][parity],
                                                mod.mul(mod.mul(last[j - 1][k][t - 1][1 - parity], compEven[k]), pow2[i - t - k]));
                                    }

                                    //pick odd and it's even
                                    next[j][k][t][parity] = mod.plus(next[j][k][t][parity],
                                            mod.mul(mod.mul(last[j][k][t - 1][parity], compOdd[k]), pow2[i - t - k]));
                                }
                                if (c[i] != 0) {
                                    //it's 1 now

                                    //pick even and it's odd
                                    if (k > 0) {
                                        next[j][k][t][parity] = mod.plus(next[j][k][t][parity],
                                                mod.mul(mod.mul(last[j][k - 1][t][1 - parity], compEven[j]), pow2[t - j]));
                                    }

                                    //pick odd and it's even
                                    next[j][k][t][parity] = mod.plus(next[j][k][t][parity],
                                            mod.mul(mod.mul(last[j][k][t][parity], compOdd[j]), pow2[t - j]));
                                }
                            }
                        }
                    }
                }

                int[][][][] tmp = last;
                last = next;
                next = tmp;
            }

            int ans = 0;
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= n; j++) {
                    for (int k = 0; k <= n; k++) {
                        int cnt = last[i][j][k][p];
                        cnt = mod.mul(cnt, pow.pow(comp.composite(k, 2)));
                        cnt = mod.mul(cnt, pow.pow(comp.composite(n - k, 2)));
                        ans = mod.plus(ans, cnt);
                    }
                }
            }

            out.println(ans);
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static long round(double x) {
            if (x >= 0) {
                return (long) (x + 0.5);
            } else {
                return (long) (x - 0.5);
            }
        }

    }

    static class Composite {
        final Factorial factorial;
        final Modular modular;

        public Composite(Factorial factorial) {
            this.factorial = factorial;
            this.modular = factorial.getModular();
        }

        public Composite(int limit, Modular modular) {
            this(new Factorial(limit, modular));
        }

        public int composite(int m, int n) {
            if (n > m) {
                return 0;
            }
            return modular.mul(modular.mul(factorial.fact(m), factorial.invFact(n)), factorial.invFact(m - n));
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(int c) {
            cache.append(c).append('\n');
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public int valueOf(int x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return x;
        }

        public int valueOf(long x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return (int) x;
        }

        public int mul(int x, int y) {
            return valueOf((long) x * y);
        }

        public int plus(int x, int y) {
            return valueOf(x + y);
        }

        public Modular getModularForPowerComputation() {
            return new Modular(m - 1);
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static class InverseNumber {
        int[] inv;

        public InverseNumber(int[] inv, int limit, Modular modular) {
            this.inv = inv;
            inv[1] = 1;
            int p = modular.getMod();
            for (int i = 2; i <= limit; i++) {
                int k = p / i;
                int r = p % i;
                inv[i] = modular.mul(-k, inv[r]);
            }
        }

        public InverseNumber(int limit, Modular modular) {
            this(new int[limit + 1], limit, modular);
        }

    }

    static class CachedPow {
        private int[] first;
        private int[] second;
        private Modular mod;
        private Modular powMod;

        public CachedPow(int x, Modular mod) {
            this(x, mod.getMod(), mod);
        }

        public CachedPow(int x, int maxExp, Modular mod) {
            this.mod = mod;
            this.powMod = mod.getModularForPowerComputation();
            int k = Math.max(1, (int) DigitUtils.round(Math.sqrt(maxExp)));
            first = new int[k];
            second = new int[maxExp / k + 1];
            first[0] = 1;
            for (int i = 1; i < k; i++) {
                first[i] = mod.mul(x, first[i - 1]);
            }
            second[0] = 1;
            int step = mod.mul(x, first[k - 1]);
            for (int i = 1; i < second.length; i++) {
                second[i] = mod.mul(second[i - 1], step);
            }
        }

        public int pow(int exp) {
            return mod.mul(first[exp % first.length], second[exp / first.length]);
        }

    }

    static class Factorial {
        int[] fact;
        int[] inv;
        Modular modular;

        public Modular getModular() {
            return modular;
        }

        public Factorial(int[] fact, int[] inv, InverseNumber in, int limit, Modular modular) {
            this.modular = modular;
            this.fact = fact;
            this.inv = inv;
            fact[0] = inv[0] = 1;
            for (int i = 1; i <= limit; i++) {
                fact[i] = modular.mul(fact[i - 1], i);
                inv[i] = modular.mul(inv[i - 1], in.inv[i]);
            }
        }

        public Factorial(int limit, Modular modular) {
            this(new int[limit + 1], new int[limit + 1], new InverseNumber(limit, modular), limit, modular);
        }

        public int fact(int n) {
            return fact[n];
        }

        public int invFact(int n) {
            return inv[n];
        }

    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Div2_482E {

	static int nV;
	static int p;

	static int[] color;

	static long[] pow2;

	static long[][][][] dp;

	static long MOD = 1_000_000_007;

	public static void main(String[] args) throws IOException {
		pow2 = new long[500];
		pow2[0] = 1;
		for (int i = 1; i < 500; i++) {
			pow2[i] = pow2[i - 1] * 2 % MOD;
		}

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		nV = Integer.parseInt(inputData.nextToken());
		p = Integer.parseInt(inputData.nextToken());

		color = new int[nV];
		inputData = new StringTokenizer(reader.readLine());
		for (int i = 0; i < nV; i++) {
			color[i] = Integer.parseInt(inputData.nextToken());
		}

		dp = new long[nV + 1][nV + 1][nV + 1][nV + 1];
		dp[nV][0][0][0] = 1;
		pushDP(nV, 0, 0, 0);

		for (int cV = nV - 1; cV > 0; cV--) {
			for (int i = 0; i <= nV; i++) {
				for (int j = 0; j <= nV; j++) {
					for (int k = 0; k <= nV; k++) {
						int l = nV - cV - i - j - k;
						if (l >= 0 && dp[cV][i][j][k] != 0) {
							pushDP(cV, i, j, k);
						}
					}
				}
			}
		}
		long ans = 0;
		for (int wE = 0; wE <= nV; wE++) {
			for (int wO = 0; wO <= nV; wO++) {
				for (int bE = 0; bE <= nV; bE++) {
					int bO = nV - wE - wO - bE;

					if (bO >= 0 && ((wO + bO) & 1) == p) {
						ans = (ans + dp[0][wE][wO][bE]) % MOD;
					}
				}
			}
		}
		printer.println(ans);
		printer.close();
	}

	static void pushDP(int cV, int wE, int wO, int bE) {
		int bO = nV - cV - wE - wO - bE;
		long cDP = dp[cV][wE][wO][bE];
		if (cDP == 0) {
			return;
		}

		// white
		if (color[cV - 1] == 0 || color[cV - 1] == -1) {
			if (bO != 0) {
				dp[cV - 1][wE + 1][wO][bE] = (dp[cV - 1][wE + 1][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
				dp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
			} else {
				dp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bE] * cDP) % MOD;
			}
		}
		// black
		if (color[cV - 1] == 1 || color[cV - 1] == -1) {
			if (wO != 0) {
				dp[cV - 1][wE][wO][bE + 1] = (dp[cV - 1][wE][wO][bE + 1] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
				dp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
			} else {
				dp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wE + bE + bO] * cDP) % MOD;
			}
		}
	}

}

import java.util.ArrayList;
import java.util.Scanner;
import java.lang.StringBuilder;
import java.util.Arrays;
import java.util.Stack;
import java.util.TreeMap;
public class Test10   {
    //suppose: a[0] black
    //maintain: array a[i][j]: number of coloring w/ pointer on i with j black vertices to right:
    //if a[i] black: a[i][j] = a[i - 1][j + 1];
    //if a[i] white:a[i][j] = total possible / 4(2 if j = 0) + 2 ^ (i + j - 1) * a[i - 1][j];
    //total possible = 2 ^ (undecided + (i + j + 1) * (i + j) / 2)
    //if a[i] ambiguous: a[i][j] = sum of two
    //maintain on i
    public static void main(String[] Args)   {
        long huge = 1000000007;
        long[][] a = new long[51][51];
        long ans = 0;
        long[] pw2 = new long[5001];
        pw2[0] = 1;
        for (int i = 0; i <= 4999; i++)
            pw2[i + 1] = (pw2[i] * 2)%huge;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
                int p = sc.nextInt();
        int[] cl = new int[n];
        for (int i = 0; i < n; i++) cl[i] = sc.nextInt();

        if (cl[0] == -1 || cl[0] == 0)   {
            for (int i = 0; i <= 50; i++)  {
                if (i % 2 != p) a[0][i] = pw2[(i *(i + 1))/2];
                else a[0][i] = 0;
            }
            int undecided = 0;
            for (int i = 1; i <= n - 1; i++)  {
                for (int j = 0; j <= n - 1 - i; j++)   {
                    a[i][j] = 0;
                    if (cl[i] == 0 || cl[i] == -1)   {
                        a[i][j] += a[i - 1][j + 1];
                    }
                    if (cl[i] == 1 || cl[i] == -1)   {
                        if (j == 0) a[i][j] += pw2[undecided + ((i + j + 1) * (i + j)) / 2 - 1];
                        else {
                            a[i][j] += pw2[undecided + ((i + j + 1) * (i + j)) / 2 - 2];
                            a[i][j] += pw2[i + j - 1] * a[i - 1][j];
                        }
                    }
                    a[i][j] = a[i][j] % huge;
                }
                if (cl[i] == -1) undecided++;
            }
            ans += a[n - 1][0];
        }
        a = new long[51][51];
        if (cl[0] == -1 || cl[0] == 1)   {
            for (int i = 0; i <= 50; i++)  {
                if (i % 2 != p) a[0][i] = pw2[(i *(i + 1))/2];
                else a[0][i] = 0;
            }
            int undecided = 0;
            for (int i = 1; i <= n - 1; i++)  {
                for (int j = 0; j <= n - 1 - i; j++)   {
                    a[i][j] = 0;
                    if (cl[i] == 1 || cl[i] == -1)   {
                        a[i][j] += a[i - 1][j + 1];
                    }
                    if (cl[i] == 0 || cl[i] == -1)   {
                        if (j == 0)  {
                            a[i][j] += pw2[undecided + ((i + j + 1) * (i + j)) / 2 - 1];
                        }
                        else  {
                            a[i][j] += pw2[undecided + ((i + j + 1) * (i + j)) / 2 - 2];
                            a[i][j] += pw2[i + j - 1] * a[i - 1][j];
                        }
                    }
                    a[i][j] = a[i][j] % huge;
                }
                if (cl[i] == -1) undecided++;
            }
            ans += a[n - 1][0];
        }
        System.out.println(ans % huge);
   }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class KuroAndTopologicalParity2 {

    int MOD = (int) 1e9 + 7;
    int N = 55;

    long[] p2 = new long[N];
    long[][] c = new long[N][N];
    long[][] cs = new long[N][2];

    long[][][] dp = new long[N][N][N];

    {
        p2[0] = 1;
        for (int i = 1; i < N; i++) p2[i] = p2[i - 1] * 2 % MOD;

        for (int i = 0; i < N; i++) {
            c[i][0] = 1;
            for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                cs[i][j & 1] = (cs[i][j & 1] + c[i][j]) % MOD;
            }
        }
    }

    void solve() {
        int n = in.nextInt(), p = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();

        long ans = 0;
        dp[0][0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int ob = 0; ob <= i + 1; ob++) {
                for (int ow = 0; ob + ow <= i + 1; ow++) {
                    if (a[i] != 0 && i - ob >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow] * p2[i - ob] * cs[ob][1];
                    if (a[i] != 0 && ow - 1 >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow - 1] * p2[i - ob] * cs[ob][0];
                    if (a[i] != 1 && i - ow >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow] * p2[i - ow] * cs[ow][1];
                    if (a[i] != 1 && ob - 1 >= 0) dp[i + 1][ob][ow] += dp[i][ob - 1][ow] * p2[i - ow] * cs[ow][0];
                    if (i + 1 == n && ((ob + ow) & 1) == p) ans += dp[i + 1][ob][ow];
                }
            }
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new KuroAndTopologicalParity2().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

import java.io.*;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by dalt on 2018/5/30.
 */
public class Contest472E {
    static final int INF = (int) 1e8;
    static final int MOD = (int) 1e9 + 7;
    public static BlockReader input;
    public static PrintStream output;
    public static Debug debug;

    public static void main(String[] args) throws FileNotFoundException {
        init();

        solve();

        destroy();
    }

    public static void init() throws FileNotFoundException {
        if (System.getProperty("ONLINE_JUDGE") == null) {
            input = new BlockReader(new FileInputStream("E:\\DATABASE\\TESTCASE\\codeforces\\Contest472E.in"));
            output = System.out;
        } else {
            input = new BlockReader(System.in);
            output = new PrintStream(new BufferedOutputStream(System.out), false);
        }

        debug = new Debug();
        debug.enter("main");
    }

    public static void solve() {
        int n = input.nextInteger();
        int p = input.nextInteger();

        long[][][] dp = new long[n][2][2];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = input.nextInteger();
        }

        for (int i = n - 1; i >= 0; i--) {
            long[] cnt = new long[2];
            long[][] localDp = new long[2][2];

            if (c[i] == -1) {
                dp[i][0][1] = localDp[0][1] = 1;
                dp[i][1][1] = localDp[1][1] = 1;
            } else {
                dp[i][c[i]][1] = localDp[c[i]][1] = 1;
            }

            int num = n - 2 - i >= 0 ? Mathematics.pow(2,  (n - 2 - i), MOD) : 0;
            for (int j = i + 1; j < n; j++) {
                if (c[j] == -1 || c[j] == 0) {
                    dp[i][1][0] = (dp[i][1][0] + (localDp[1][0] * dp[j][0][0] + localDp[1][1] * dp[j][0][1]) * num) % MOD;
                    dp[i][1][1] = (dp[i][1][1] + (localDp[1][1] * dp[j][0][0] + localDp[1][0] * dp[j][0][1]) * num) % MOD;
                }
            }
            for (int j = i + 1; j < n; j++) {
                if (c[j] == -1 || c[j] == 1) {
                    dp[i][0][0] = (dp[i][0][0] + (localDp[0][0] * dp[j][1][0] + localDp[0][1] * dp[j][1][1]) * num) % MOD;
                    dp[i][0][1] = (dp[i][0][1] + (localDp[0][1] * dp[j][1][0] + localDp[0][0] * dp[j][1][1]) * num) % MOD;
                }
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum = sum + dp[i][0][p] + dp[i][1][p];
        }
        sum %= MOD;
        output.println(sum);
    }

    public static void destroy() {
        output.flush();
        debug.exit();
        debug.statistic();
    }

    public static class Debug {
        boolean debug = System.getProperty("ONLINE_JUDGE") == null;
        Deque<ModuleRecorder> stack = new ArrayDeque<>();
        Map<String, Module> fragmentMap = new HashMap<>();

        public void enter(String module) {
            if (debug) {
                stack.push(new ModuleRecorder(getModule(module)));
            }
        }

        public Module getModule(String moduleName) {
            Module module = fragmentMap.get(moduleName);
            if (module == null) {
                module = new Module(moduleName);
                fragmentMap.put(moduleName, module);
            }
            return module;
        }

        public void exit() {
            if (debug) {
                ModuleRecorder fragment = stack.pop();
                fragment.exit();
            }
        }

        public void statistic() {
            if (!debug) {
                return;
            }

            if (stack.size() > 0) {
                throw new RuntimeException("Exist unexited tag");
            }
            System.out.println("\n------------------------------------------");

            System.out.println("memory used " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + "M");

            System.out.println("\n------------------------------------------");
            for (Module module : fragmentMap.values()) {
                System.out.println(String.format("Module %s : enter %d : cost %d", module.moduleName, module.enterTime, module.totaltime));
            }

            System.out.println("------------------------------------------");
        }

        public static class ModuleRecorder {
            Module fragment;
            long time;

            public ModuleRecorder(Module fragment) {
                this.fragment = fragment;
                time = System.currentTimeMillis();
            }

            public void exit() {
                fragment.totaltime += System.currentTimeMillis() - time;
                fragment.enterTime++;
            }
        }

        public static class Module {
            String moduleName;
            long totaltime;
            long enterTime;

            public Module(String moduleName) {
                this.moduleName = moduleName;
            }
        }
    }

    public static class BlockReader {
        static final int EOF = -1;
        InputStream is;
        byte[] dBuf;
        int dPos, dSize, next;
        StringBuilder builder = new StringBuilder();

        public BlockReader(InputStream is) {
            this(is, 8192);
        }

        public BlockReader(InputStream is, int bufSize) {
            this.is = is;
            dBuf = new byte[bufSize];
            next = nextByte();
        }

        public int nextByte() {
            while (dPos >= dSize) {
                if (dSize == -1) {
                    return EOF;
                }
                dPos = 0;
                try {
                    dSize = is.read(dBuf);
                } catch (Exception e) {
                }
            }
            return dBuf[dPos++];
        }

        public String nextBlock() {
            builder.setLength(0);
            skipBlank();
            while (next != EOF && !Character.isWhitespace(next)) {
                builder.append((char) next);
                next = nextByte();
            }
            return builder.toString();
        }

        public void skipBlank() {
            while (Character.isWhitespace(next)) {
                next = nextByte();
            }
        }

        public int nextInteger() {
            skipBlank();
            int ret = 0;
            boolean rev = false;
            if (next == '+' || next == '-') {
                rev = next == '-';
                next = nextByte();
            }
            while (next >= '0' && next <= '9') {
                ret = (ret << 3) + (ret << 1) + next - '0';
                next = nextByte();
            }
            return rev ? -ret : ret;
        }

        public int nextBlock(char[] data, int offset) {
            skipBlank();
            int index = offset;
            int bound = data.length;
            while (next != EOF && index < bound && !Character.isWhitespace(next)) {
                data[index++] = (char) next;
                next = nextByte();
            }
            return index - offset;
        }

        public boolean hasMore() {
            skipBlank();
            return next != EOF;
        }
    }

    public static class Mathematics {
        public static int gcd(int a, int b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

        public static int gcd0(int a, int b) {
            return b == 0 ? a : gcd0(b, a % b);
        }

        public static long gcd(long a, long b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

        public static long gcd0(long a, long b) {
            return b == 0 ? a : gcd0(b, a % b);
        }

        public static int inverse(int x, int mod) {
            return pow(x, mod - 2, mod);
        }

        public static int pow(int x, int n, int mod) {
            n = mod(n, mod - 1);
            x = mod(x, mod);
            int bit = 31 - Integer.numberOfLeadingZeros(n);
            long product = 1;
            for (; bit >= 0; bit--) {
                product = product * product % mod;
                if (((1 << bit) & n) != 0) {
                    product = product * x % mod;
                }
            }
            return (int) product;
        }

        public static int mod(int x, int mod) {
            return x >= 0 ? x % mod : (((x % mod) + mod) % mod);
        }

        public static long cross(int x1, int y1, int x2, int y2) {
            return (long) x1 * y2 - (long) y1 * x2;
        }

        public static double cross(double x1, double y1, double x2, double y2) {
            return x1 * y2 - y1 * x2;
        }

        public static long permute(int n, int m) {
            return m == 0 ? 1 : n * permute(n - 1, m - 1);
        }

        public static int eulerSieve(int limit, int[] primes, int offset) {
            boolean[] isComp = new boolean[limit + 1];
            int wpos = offset;
            for (int i = 2; i <= limit; i++) {
                if (!isComp[i]) {
                    primes[wpos++] = i;
                }
                for (int j = offset, until = limit / i; j < wpos && primes[j] <= until; j++) {
                    int pi = primes[j] * i;
                    isComp[pi] = true;
                    if (i % primes[j] == 0) {
                        break;
                    }
                }
            }
            return wpos - offset;
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            EKuroAndTopologicalParity solver = new EKuroAndTopologicalParity();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class EKuroAndTopologicalParity {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int p = in.readInt();

            Modular mod = new Modular(1e9 + 7);
            CachedPow pow = new CachedPow(2, n, mod);

            int[][][][] dp = new int[n + 1][2][2][2];
            dp[0][0][0][0] = 1;

            for (int i = 1; i <= n; i++) {
                int c = in.readInt();

                for (int j = 0; j < 2; j++) {
                    for (int k = 0; k < 2; k++) {
                        for (int t = 0; t < 2; t++) {
                            int cnt = i - 2 >= 0 ? pow.pow(i - 2) : 1;

                            if (c != 1 && k == 1) {
                                //pick odd
                                if (t == 1) {
                                    dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][j][1][t], dp[i - 1][j][0][t]), cnt));
                                }
                                //pick even
                                dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][1 - j][1][t], dp[i - 1][1 - j][0][t]), cnt));
                            }
                            if (c != 0 && t == 1) {
                                //pick odd
                                if (k == 1) {
                                    dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][j][k][1], dp[i - 1][j][k][0]), cnt));
                                }
                                //pick even
                                dp[i][j][k][t] = mod.plus(dp[i][j][k][t], mod.mul(mod.plus(dp[i - 1][1 - j][k][1], dp[i - 1][1 - j][k][0]), cnt));
                            }
                        }
                    }
                }
            }

            int ans = 0;
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    ans = mod.plus(dp[n][p][i][j], ans);
                }
            }

            out.println(ans);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(int c) {
            cache.append(c).append('\n');
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public int valueOf(int x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return x;
        }

        public int valueOf(long x) {
            x %= m;
            if (x < 0) {
                x += m;
            }
            return (int) x;
        }

        public int mul(int x, int y) {
            return valueOf((long) x * y);
        }

        public int plus(int x, int y) {
            return valueOf(x + y);
        }

        public Modular getModularForPowerComputation() {
            return new Modular(m - 1);
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static class CachedPow {
        private int[] first;
        private int[] second;
        private Modular mod;
        private Modular powMod;

        public CachedPow(int x, Modular mod) {
            this(x, mod.getMod(), mod);
        }

        public CachedPow(int x, int maxExp, Modular mod) {
            this.mod = mod;
            this.powMod = mod.getModularForPowerComputation();
            int k = Math.max(1, (int) DigitUtils.round(Math.sqrt(maxExp)));
            first = new int[k];
            second = new int[maxExp / k + 1];
            first[0] = 1;
            for (int i = 1; i < k; i++) {
                first[i] = mod.mul(x, first[i - 1]);
            }
            second[0] = 1;
            int step = mod.mul(x, first[k - 1]);
            for (int i = 1; i < second.length; i++) {
                second[i] = mod.mul(second[i - 1], step);
            }
        }

        public int pow(int exp) {
            return mod.mul(first[exp % first.length], second[exp / first.length]);
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static long round(double x) {
            if (x >= 0) {
                return (long) (x + 0.5);
            } else {
                return (long) (x - 0.5);
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Div2_482E {

	static int nV;
	static int p;

	static int[] color;

	static long[] pow2;

	static long[][][][] dp;

	static long MOD = 1_000_000_007;

	public static void main(String[] args) throws IOException {
		pow2 = new long[500];
		pow2[0] = 1;
		for (int i = 1; i < 500; i++) {
			pow2[i] = pow2[i - 1] * 2 % MOD;
		}

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		nV = Integer.parseInt(inputData.nextToken());
		p = Integer.parseInt(inputData.nextToken());

		color = new int[nV];
		inputData = new StringTokenizer(reader.readLine());
		for (int i = 0; i < nV; i++) {
			color[i] = Integer.parseInt(inputData.nextToken());
		}

		dp = new long[nV + 1][nV + 1][nV + 1][nV + 1];
		dp[nV][0][0][0] = 1;
		pushDP(nV, 0, 0, 0);

		for (int cV = nV - 1; cV > 0; cV--) {
			for (int i = 0; i <= nV; i++) {
				for (int j = 0; j <= nV; j++) {
					for (int k = 0; k <= nV; k++) {
						int l = nV - cV - i - j - k;
						if (l >= 0 && dp[cV][i][j][k] != 0) {
							pushDP(cV, i, j, k);
						}
					}
				}
			}
		}
		long ans = 0;
		for (int wE = 0; wE <= nV; wE++) {
			for (int wO = 0; wO <= nV; wO++) {
				for (int bE = 0; bE <= nV; bE++) {
					int bO = nV - wE - wO - bE;

					if (((wO + bO) & 1) == p) {
						ans = (ans + dp[0][wE][wO][bE]) % MOD;
					}
				}
			}
		}
		printer.println(ans);
		printer.close();
	}

	static void pushDP(int cV, int wE, int wO, int bE) {
		int bO = nV - cV - wE - wO - bE;
		long cDP = dp[cV][wE][wO][bE];
		if (cDP == 0) {
			return;
		}

		// white
		if (color[cV - 1] == 0 || color[cV - 1] == -1) {
			if (bO != 0) {
				dp[cV - 1][wE + 1][wO][bE] = (dp[cV - 1][wE + 1][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
				dp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
			} else {
				dp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bO] * cDP) % MOD;
			}
		}
		// black
		if (color[cV - 1] == 1 || color[cV - 1] == -1) {
			if (wO != 0) {
				dp[cV - 1][wE][wO][bE + 1] = (dp[cV - 1][wE][wO][bE + 1] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
				dp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;
			} else {
				dp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wO + bE + bO] * cDP) % MOD;
			}
		}
	}

}