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

public class CF413D {
	static int M = 1000000007;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(br.readLine());
		int[] aa = new int[n];
		for (int i = 0; i < n; i++)
			aa[i] = Integer.parseInt(st.nextToken());
		long[] zz = new long[n + 1];
		zz[n] = 1;
		for (int i = n - 1; i >= 0; i--)
			zz[i] = (zz[i + 1] * (aa[i] == 0 ? 2 : 1)) % M;
		int[][] dp = new int[1 << k][n + 1];
		dp[0][0] = 1;
		for (int i = 0; i < n; i++)
			for (int b = i == 0 ? 0 : 1; b < 1 << k; b++)
				if (dp[b][i] > 0) {
					if (aa[i] != 0) {
						int b_ = (b + aa[i]) % (1 << k);
						dp[b_][i + 1] = (dp[b_][i + 1] + dp[b][i]) % M;
					} else {
						int b2 = (b + 2) % (1 << k);
						dp[b2][i + 1] = (dp[b2][i + 1] + dp[b][i]) % M;
						int b4 = (b + 4) % (1 << k);
						dp[b4][i + 1] = (dp[b4][i + 1] + dp[b][i]) % M;
					}
				}
		long sum = 0;
		for (int i = 1; i <= n; i++)
			sum = (sum + dp[0][i] * zz[i]) % M;
		System.out.println(sum);
	}
}


import java.io.*;
import java.net.URL;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    boolean has(int mask, int bit) {
        return (mask & (1 << bit)) != 0;
    }

    int convertMask(int mask, int curAdd) {
        if (mask == 0) return curAdd;
        int smallBit = Integer.lowestOneBit(mask);
        if (smallBit < curAdd) return curAdd;
        return mask + curAdd;
    }

    void solve() throws IOException {
        int n = readInt();
        int k = readInt();
        int[] a = readIntArray(n);
        int max = 1 << 12;
        int mod = (int) 1e9 + 7;
        int[][] count = new int[n + 1][max];
        count[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < max; j++) {
                if (count[i][j] == 0) continue;
                if (has(j, k)) {
                    count[i + 1][j] += count[i][j];
                    count[i + 1][j] %= mod;
                    if (a[i] == 0) {
                        count[i + 1][j] += count[i][j];
                        count[i + 1][j] %= mod;
                    }
                    continue;
                }
                if (a[i] == 2 || a[i] == 0) {
                    int nextM = convertMask(j, 2);
                    count[i + 1][nextM] += count[i][j];
                    count[i + 1][nextM] %= mod;
                }
                if (a[i] == 4 || a[i] == 0) {
                    int nextM = convertMask(j, 4);
                    count[i + 1][nextM] += count[i][j];
                    count[i + 1][nextM] %= mod;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < max; i++) {
            if (has(i, k)) {
                ans += count[n][i];
                ans %= mod;
            }
        }
        out.println(ans);
    }

}


import java.util.*;
public class CodeforcesD413 {
	public static int n, k;
	public static int[][] memo;
	public static int[] nums;
	public static int mod = 1000000007;
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		n = br.nextInt();
		k = br.nextInt();
		nums = new int[n];
		for(int i = 0;i<n;i++){
			nums[i] = br.nextInt();
		}

		memo = new int[n][1<<k];
		for(int i = 0;i<n;i++){
			Arrays.fill(memo[i], -1);
		}

		System.out.println(go(0, 0));
	}
	public static int go(int pos, int mask){
		if(pos == n){
			if((mask&(1<<(k-1))) > 0){
				return 1;
			}
			return 0;
		}
		if(memo[pos][mask] != -1){
			return memo[pos][mask];
		}
		int ans = 0;
		if((mask & (1<<(k-1))) > 0){
			if(nums[pos] == 0){
				ans+=go(pos+1, mask);
				ans+=go(pos+1, mask);
			}
			else{
				ans+=go(pos+1, mask);
			}
			return memo[pos][mask] = ans%mod;
		}

		if(nums[pos] != 4){
			ans+=go(pos+1, mask+1);
		}
		if(nums[pos] != 2){
			int nmask = mask;
			if(mask%2 == 1){
				nmask = 0;
			}
			ans+=go(pos+1, nmask+2);
		}
		return memo[pos][mask] = ans%mod;
	}
}


import java.util.*;
public class CodeforcesD413 {
	public static int n, k;
	public static int[][] memo;
	public static int[] nums;
	public static int mod = 1000000007;
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		n = br.nextInt();
		k = br.nextInt();
		nums = new int[n];
		for(int i = 0;i<n;i++){
			nums[i] = br.nextInt();
		}

		memo = new int[n][1<<k];
		for(int i = 0;i<n;i++){
			Arrays.fill(memo[i], -1);
		}

		System.out.println(go(0, 0));
	}
	public static int go(int pos, int mask){
		if(pos == n){
			if((mask&(1<<(k-1))) > 0){
				return 1;
			}
			return 0;
		}
		if(memo[pos][mask] != -1){
			return memo[pos][mask];
		}
		int ans = 0;
		if((mask & (1<<(k-1))) > 0){
			if(nums[pos] == 0){
				ans+=go(pos+1, mask);
				ans+=go(pos+1, mask);
			}
			else{
				ans+=go(pos+1, mask);
			}
			return memo[pos][mask] = ans%mod;
		}

		if(nums[pos] != 4){
			ans+=go(pos+1, mask+1);
		}
		if(nums[pos] != 2){
			int nmask = mask;
			if(mask%2 == 1){
				nmask-=1;
			}
			ans+=go(pos+1, nmask+2);
		}
		return memo[pos][mask] = ans%mod;
	}
}


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

public class Main {

	static int[][] look;
	static int p=1000000007;
	static int n;
	static int k;
	static int kk;
	static int[] list;
	public static void main(String[] args) throws IOException {

		//BufferedReader cin = new BufferedReader(new FileReader("te.txt"));
		 BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));

		String line;
		StringTokenizer st;

		line=cin.readLine();
		st=new StringTokenizer(line);
		n=Integer.parseInt(st.nextToken());
		k=Integer.parseInt(st.nextToken());
		kk=1<<k;
		list = new int[n];
		look=new int[n+1][kk+1];
		for(int[] row:look) Arrays.fill(row,-1);
		line=cin.readLine();
		st = new StringTokenizer(line);
		for(int i=0;i<n;i++){
			list[i]=Integer.parseInt(st.nextToken());
		}
		System.out.println(dp(0,0));

		cin.close();
	}

	public static int dp(int ind, int mask){
		if(look[ind][mask]>-1) return look[ind][mask];
		if(ind==n)return look[ind][mask]=(mask>=kk)?1:0;//base case
		if(list[ind]!=0){//2 or 4
			if((mask&2)==2&&list[ind]==4){
				return look[ind][mask]=dp(ind+1,4);
			}else{
				return look[ind][mask]=dp(ind+1,mask+list[ind]);
			}
		}
		else{
			if((mask&2)==2)//last ele is 2
				return look[ind][mask]=(dp(ind+1,mask+2)//fill a 2
				                      +dp(ind+1,4))%p;//fill a 4
			else
				return look[ind][mask]=(dp(ind+1,mask+2)+dp(ind+1,mask+4))%p;
		}
	}

}


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

public class Main {

	static int[][] look;
	static int p=1000000007;
	static int n;
	static int k;
	static int kk;
	static int[] list;
	public static void main(String[] args) throws IOException {

		//BufferedReader cin = new BufferedReader(new FileReader("te.txt"));
		 BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));

		String line;
		StringTokenizer st;

		line=cin.readLine();
		st=new StringTokenizer(line);
		n=Integer.parseInt(st.nextToken());
		k=Integer.parseInt(st.nextToken());
		kk=1<<k;
		list = new int[n];
		look=new int[n+1][kk+1];
		for(int[] row:look) Arrays.fill(row,-1);
		line=cin.readLine();
		st = new StringTokenizer(line);
		for(int i=0;i<n;i++){
			list[i]=Integer.parseInt(st.nextToken());
		}
		System.out.println(dp(0,0));

		cin.close();
	}

	public static int dp(int ind, int mask){
		if(look[ind][mask]>-1) return look[ind][mask];
		if(ind==n)return look[ind][mask]=(mask>=kk)?1:0;//base case
		if(list[ind]!=0){//2 or 4
			if((mask&2)==2&&list[ind]==4){
				return look[ind][mask]=dp(ind+1,4);
			}else{
				return look[ind][mask]=dp(ind+1,Math.min(mask+list[ind],kk));
			}
		}
		else{
			if((mask&2)==2)//last ele is 2
				return look[ind][mask]=(dp(ind+1,Math.min(mask+2,kk))//fill a 2
				                      +dp(ind+1,4))%p;//fill a 4
			else
				return look[ind][mask]=(dp(ind+1,Math.min(mask+2,kk))+dp(ind+1,Math.min(mask+4,kk)))%p;
		}
	}

}


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

public class Main {

	static int[][] look;
	static int p=1000000007;
	static int n;
	static int k;
	static int kk;
	static int[] list;
	public static void main(String[] args) throws IOException {

		BufferedReader cin = new BufferedReader(new FileReader("te.txt"));
		 //BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));

		String line;
		StringTokenizer st;

		line=cin.readLine();
		st=new StringTokenizer(line);
		n=Integer.parseInt(st.nextToken());
		k=Integer.parseInt(st.nextToken());
		kk=1<<k;
		list = new int[n];
		look=new int[n+1][kk+1];
		for(int[] row:look) Arrays.fill(row,-1);
		line=cin.readLine();
		st = new StringTokenizer(line);
		for(int i=0;i<n;i++){
			list[i]=Integer.parseInt(st.nextToken());
		}
		System.out.println(dp(0,0));

		cin.close();
	}

	public static int dp(int ind, int mask){
		if(look[ind][mask]>-1) return look[ind][mask];
		if(ind==n)return look[ind][mask]=(mask>=kk)?1:0;//base case
		if(list[ind]!=0){//2 or 4
			if((mask&2)==2&&list[ind]==4){
				return look[ind][mask]=dp(ind+1,4);
			}else{
				return look[ind][mask]=dp(ind+1,Math.min(mask+list[ind],kk));
			}
		}
		else{
			if((mask&2)==2)//last ele is 2
				return look[ind][mask]=(dp(ind+1,Math.min(mask+2,kk))//fill a 2
				                      +dp(ind+1,4))%p;//fill a 4
			else
				return look[ind][mask]=(dp(ind+1,Math.min(mask+2,kk))+dp(ind+1,Math.min(mask+4,kk)))%p;
		}
	}

}


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

public class d413 {
	public static void main(String[] args) {
		new d413();
	}
	Scanner in = new Scanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	int n, k, sz, mod = (int)1e9+7;
	int[] state, two, zer;
	int[][] dp;

	d413() {
		// for (;;) {
			n = in.nextInt();
			// if (n == 0)
				// break;
			k = in.nextInt();
			state = new int[n];
			for (int i = 0; i < n; i++)
				state[i] = in.nextInt();
			dp = new int[(1 << k)+1][n];
			for (int i = 0; i <= (1 << k); i++)
				Arrays.fill(dp[i], -1);

			sz = Math.max(n+1, k+1);
			two = new int[sz];
			two[0] = 1;
			for (int i = 1; i < sz; i++)
				two[i] = 2*two[i-1] % mod;
			zer = new int[n+1];
			for (int i = n-1; i >= 0; i--)
				zer[i] = (state[i] == 0 ? 1 : 0)+zer[i+1];
			out.println(dp(0, 0));
		// }
		out.close();
	}

	int dp(int mask, int i) {
		if (mask > 0 && mask %two[k] == 0)
			return two[zer[i]];
		if (i == n)
			return 0;
		if (dp[mask][i] != -1)
			return dp[mask][i];

		int j = state[i];
		if (state[i] != 0) {
			if (mask %j == 0)
				return dp(mask+j, i+1);
			else
				return dp(j, i+1);
		}

		int ans = 0;
		if (mask %2 == 0)
			ans += dp(mask+2, i+1);
		else
			ans += dp(2, i+1);
		ans %= mod;
		if (mask %4 == 0)
			ans += dp(mask+4, i+1);
		else
			ans += dp(4, i+1);
		ans %= mod;

		return dp[mask][i] = ans;
	}
}


//package strike2014.r2;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), K = ni();
		int[] a = na(n);
		int[] pre = new int[(1<<K)+1];
		int[] cur = new int[(1<<K)+1];
		pre[0] = 1;
		int mod = 1000000007;
		for(int i = 0;i < n;i++){
			Arrays.fill(cur, 0);
			for(int j = 0;j <= 1<<K;j++){
				if(a[i] == 2 || a[i] == 0){
					int nj = Math.min(j+2, 1<<K);
					cur[nj] += pre[j];
					if(cur[nj] >= mod){
						cur[nj] -= mod;
					}
				}
				if(a[i] == 4 || a[i] == 0){
					int nj = Math.min(j+4, 1<<K);
					if(j%4!=0){
						nj = 4;
					}
					cur[nj] += pre[j];
					if(cur[nj] >= mod){
						cur[nj] -= mod;
					}
				}
			}
			int[] dum = pre; pre = cur; cur = dum;
		}
		out.println(pre[1<<K]);
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


//package strike2014.r2;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), K = ni();
		int[] a = na(n);
		int[] pre = new int[(1<<K)+1];
		int[] cur = new int[(1<<K)+1];
		pre[0] = 1;
		int mod = 1000000007;
		for(int i = 0;i < n;i++){
			Arrays.fill(cur, 0);
			for(int j = 0;j <= 1<<K;j++){
				if(a[i] == 2 || a[i] == 0){
					int nj = Math.min(j+2, 1<<K);
					cur[nj] += pre[j];
					if(cur[nj] >= mod){
						cur[nj] -= mod;
					}
				}
				if(a[i] == 4 || a[i] == 0){
					int nj = Math.min(j+4, 1<<K);
					if(j<<30<0){
						nj = 4;
					}
					cur[nj] += pre[j];
					if(cur[nj] >= mod){
						cur[nj] -= mod;
					}
				}
			}
			int[] dum = pre; pre = cur; cur = dum;
		}
		out.println(pre[1<<K]);
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define MOD 1000000007
#define MAXN 2006
int in[MAXN];
int K;
map < vector < int > , int > dp[MAXN];
bool check(vector < int > &V)
{
    int i;
    for (i=0; i<V.size(); ++i)
    {
        if (V[i] >= (1<<K)) return 1;
    }
    return 0;
}
vector < int > modify(vector < int > &V, int now)
{
    vector < int > ret;
    if (V.size() == 0 || now > V[V.size()-1])
    {
        ret.push_back(now);
        return ret;
    }
    ret = V;
    ret.push_back(now);
    int i;
    for (i=ret.size()-1; i>0; --i)
    {
        if (ret[i] != ret[i-1]) break;
        ret[i-1] += ret[i];
        ret.pop_back();
    }
    if (ret[0] >= (1<<K))
    {
        ret.clear();
        ret.push_back(1<<K);
    }
    return ret;
}
int rec (int n, vector < int > V)
{
    if (n == 0) return check(V);
    if (dp[n].find(V) != dp[n].end()) return dp[n][V];
    dp[n][V] = 0;
    int &ret = dp[n][V];
    if (in[n] <= 2) ret = rec(n-1, modify(V,2));
    if (in[n] != 2) ret += rec(n-1, modify(V,4));
    ret %= MOD;
    return ret;
}
int main()
{
    int N,i;
    vector < int > V;
    while (scanf("%d %d", &N, &K) != EOF)
    {
        for (i=1; i<=N; ++i)
        {
            scanf("%d", &in[i]);
            dp[i].clear();
        }
        reverse(in+N+1, in+1);
        V.clear();
        printf("%d\n", rec(N,V));
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define MOD 1000000007
#define MAXN 2006
int in[MAXN], zc[MAXN];
int K;
int dp[MAXN][1<<12];
bool check(int mask)
{
    if (mask >= (1<<K)) return true;
    return false;
}
int modify(int x, int now)
{
    //if (x&(1<<K)) return 1<<K;
    if (now == 2) return x+2;
    if (x&2) return 4;
    return x+4;
}
int bigmod(int a, long long k)
{
    if (k==0) return 1;
    if (k%2) return ((long long) a*bigmod(a,k-1))%MOD;
    long long ret = bigmod(a, k/2);
    return (int) ((ret*ret) % MOD);
}
int rec (int n, int mask)
{
    //printf("%d\n", n);
    if (check(mask)) return bigmod(2,zc[n]);
    if (n == 0) return 0;
    int &ret = dp[n][mask];
    if (ret != -1) return ret;
    ret = 0;
    int now;
    if (in[n] <= 2)
    {
        now = modify(mask,2);
        ret = rec(n-1, now);
    }
    if (in[n] != 2)
    {
        now = modify(mask,4);
        ret += rec(n-1, now);
    }
    ret %= MOD;
    return ret;
}
int main()
{
    //freopen("data.txt", "r", stdin);
    int N,i;
    while (scanf("%d %d", &N, &K) != EOF)
    {
        for (i=1; i<=N; ++i) scanf("%d", &in[i]);
        reverse(in+1, in+N+1);
        memset(zc, 0, sizeof(zc));
        for (i=1; i<=N; ++i)
        {
            zc[i] = zc[i-1];
            if (in[i] == 0) ++zc[i];
        }
        memset(dp, -1, sizeof(dp));
        printf("%d\n", rec(N,0));
        //break;
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define MOD 1000000007
#define MAXN 2006
int in[MAXN];
int K;
map < vector < int > , int > dp[MAXN];
bool check(vector < int > &V)
{
    int i;
    for (i=0; i<V.size(); ++i)
    {
        if (V[i] == (1<<K)) return 1;
    }
    return 0;
}
vector < int > modify(vector < int > &V, int now)
{
    vector < int > ret;
    if (V.size() == 0 || now > V[V.size()-1])
    {
        ret.push_back(now);
        return ret;
    }
    ret = V;
    ret.push_back(now);
    int i;
    for (i=ret.size()-1; i>0; --i)
    {
        if (ret[i] != ret[i-1]) break;
        ret[i-1] += ret[i];
        ret.pop_back();
    }
    if (ret[0] >= (1<<K))
    {
        ret.clear();
        ret.push_back(1<<K);
    }
    return ret;
}
int rec (int n, vector < int > V)
{
    if (n == 0) return check(V);
    if (dp[n].find(V) != dp[n].end()) return dp[n][V];
    dp[n][V] = 0;
    int &ret = dp[n][V];
    if (in[n] <= 2) ret = rec(n-1, modify(V,2));
    if (in[n] != 2) ret += rec(n-1, modify(V,4));
    ret %= MOD;
    return ret;
}
int main()
{
    int N,i;
    vector < int > V;
    while (scanf("%d %d", &N, &K) != EOF)
    {
        for (i=1; i<=N; ++i)
        {
            scanf("%d", &in[i]);
            dp[i].clear();
        }
        reverse(in+N+1, in+1);
        V.clear();
        printf("%d\n", rec(N,V));
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;typedef long long ll; ll dp [(1<<11)+2][2001];  ll num[2001];
const int MOD=pow(10,9)+7;
#define min(a,b) (a>b) ? b : a
int main()
{
    ll a,b; cin >> a >> b;
    for (ll g=1; g<=a; g++)
    {
        cin >> num[g];
    }dp[0][a+1]=1;
    for (ll g=a; g>=1; g--)
    {
        for (ll y=0; y<=(1<<b); y++)
        {
            if (num[g]!=4)
            {
                dp[min(1<<b, y+2)][g]+=dp[y][g+1]; dp[min(1<<b, y+2)][g]%=MOD;
            }
            if (num[g]!=2)
            {
                if ((y&2)!=0)
                {
                    dp[4][g]+=dp[y][g+1]; dp[4][g]%=MOD;
                }
                else
                {
                    dp[min(1<<b, y+4)][g]+=dp[y][g+1]; dp[min(1<<b,y+4)][g]%=MOD;
                }
            }
        }
    }
    cout << dp [1<<b][1] %MOD<< '\n';

}


#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;typedef long long ll; ll dp [(1<<11)+2][2001];  ll num[2001];
const int MOD=pow(10,9)+7;
#define min(a,b) (a>b) ? b : a
int main()
{
    ll a,b; cin >> a >> b;
    for (ll g=1; g<=a; g++)
    {
        cin >> num[g];
    }dp[0][0]=1;
    for (ll g=1; g<=a; g++)
    {
        for (ll y=0; y<=(1<<b); y++)
        {
            if (num[g]!=4)
            {
                dp[min(1<<b, y+2)][g]+=dp[y][g-1]; dp[min(1<<b, y+2)][g]%=MOD;
            }
            if (num[g]!=2)
            {
                if ((y&2)!=0)
                {
                    dp[4][g]+=dp[y][g-1]; dp[4][g]%=MOD;
                }
                else
                {
                    dp[min(1<<b, y+4)][g]+=dp[y][g-1]; dp[min(1<<b,y+4)][g]%=MOD;
                }
            }
        }
    }
    cout << dp [1<<b][a] %MOD<< '\n';

}


#include <iostream>
#include <vector>
#include <cmath>
#include <map>//hi
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;typedef long long ll; ll dp [(1<<11)+2][2001];  ll num[2001];
const int MOD=pow(10,9)+7;
#define min(a,b) (a>b) ? b : a
int main()
{
    ll a,b; cin >> a >> b;
    for (ll g=1; g<=a; g++)
    {
        cin >> num[g];
    }dp[0][0]=1;
    for (ll g=1; g<=a; g++)
    {
        for (ll y=0; y<=(1<<b); y++)
        {
            if (num[g]!=4)
            {
                dp[min(1<<b, y+2)][g]+=dp[y][g-1]; dp[min(1<<b, y+2)][g]%=MOD;
            }
            if (num[g]!=2)
            {
                if ((y&2)!=0)
                {
                    dp[4][g]+=dp[y][g-1]; dp[4][g]%=MOD;
                }
                else
                {
                    dp[min(1<<b, y+4)][g]+=dp[y][g-1]; dp[min(1<<b,y+4)][g]%=MOD;
                }
            }
        }
    }
    cout << dp [1<<b][a] %MOD<< '\n';

}


#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;typedef long long ll; ll dp [(1<<11)+2][2001];  ll num[2001];
const int MOD=pow(10,9)+7;
int main()
{
    ll a,b; cin >> a >> b;
    for (ll g=1; g<=a; g++)
    {
        cin >> num[g];
    }dp[0][a+1]=1;
    for (ll g=a; g>=1; g--)
    {
        for (ll y=0; y<=(1<<b); y++)
        {
            if (num[g]!=4)
            {
                dp[min(1<<b, y+2)][g]+=dp[y][g+1]; dp[min(1<<b, y+2)][g]%=MOD;
            }
            if (num[g]!=2)
            {
                if ((y&2)!=0)
                {
                    dp[4][g]+=dp[y][g+1]; dp[4][g]%=MOD;
                }
                else
                {
                    dp[min(1<<b, y+4)][g]+=dp[y][g+1]; dp[min(1<<b,y+4)][g]%=MOD;
                }
            }
        }
    }
    cout << dp [1<<b][1] %MOD<< '\n';

}


#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;typedef long long ll; int dp [(1<<11)+2][2001];  int num[2001];
const int MOD=pow(10,9)+7;
int main()
{
    int a,b; cin >> a >> b;
    for (int g=1; g<=a; g++)
    {
        cin >> num[g];
    }dp[0][a+1]=1;
    for (int g=a; g>=1; g--)
    {
        for (int y=0; y<=(1<<b); y++)
        {
            if (num[g]!=4)
            {
                dp[min(1<<b, y+2)][g]+=dp[y][g+1]; dp[min(1<<b, y+2)][g]%=MOD;
            }
            if (num[g]!=2)
            {
                if ((y&2)!=0)
                {
                    dp[4][g]+=dp[y][g+1]; dp[4][g]%=MOD;
                }
                else
                {
                    dp[min(1<<b, y+4)][g]+=dp[y][g+1]; dp[min(1<<b,y+4)][g]%=MOD;
                }
            }
        }
    }
    cout << dp [1<<b][1] %MOD<< '\n';

}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <list>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>

using namespace std;

#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <double, double> pdd;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}

template <class T> inline T max1(T a, T b) { return a > b ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }

inline int jud(double a, double b){
	if(abs(a) < eps && abs(b) < eps) return 0;
	else if(abs1(a - b) / abs1(a) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <typename t> inline int jud(t a, t b){
	if(a < b) return -1;
	if(a == b) return 0;
	return 1;
}

// f_lb == 1��?����ͬ��һ������߽磬f_small == 1��?�����û��Ѱ�ҵ�ֵ����С����
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
	int be = 0, en = na - 1;
	if(*a <= *(a + na - 1)){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(*(a + be), val) == 1) be--;
		if(!f_small && jud(*(a + be), val) == -1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(*(a + be), val) == -1) be--;
		if(f_small && jud(*(a + be), val) == 1) be++;
	}
	return be;
}

template <class T> inline T lowb(T num) {return num & (-num); }
inline int bitnum(ui nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(ull nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitnum(ll nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitmaxl(ui a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(int a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(ull a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
inline int bitmaxl(ll a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }

long long pow(long long n, long long m, long long mod = 0){
	if(m < 0) return 0;
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

//#define debug
//.........................mi.......feng......xian.......xia.......jin.......zhi.......hack...............................................

const int mod = 1000000007;
const int maxn = 2210;
int n, k;
ll dp[maxn][maxn];

inline void add(ll &a, ll b) {
	a += b;
	if(a >= mod) a -= mod;
}
int main(){
    ios_base::sync_with_stdio(0);
	#ifdef debug //......................................................................................................
	freopen("input.txt", "r", stdin);
	#endif //...........................................................................................................
	dp[0][0] = 1;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) {
		int temp;
		scanf("%d", &temp);
		for(int j = 0; j < 1 << k; j += 2) if(dp[i][j]){
			if(temp != 4) {
				int nxt = min(2 + j, (1 << k));
				add(dp[i + 1][nxt], dp[i][j]);
			}
			if(temp != 2) {
				int nxt = min(4 + j, (1 << k));
				if(j & 2) nxt = 4;
				add(dp[i + 1][nxt], dp[i][j]);
			}
		}
		add(dp[i + 1][1 << k], dp[i][1 << k] * (1 + (temp == 0)) % mod);
	}
	cout << dp[n][1 << k] << endl;

    return 0;
}


/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <list>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>

using namespace std;

#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <double, double> pdd;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}

template <class T> inline T max1(T a, T b) { return a > b ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }

inline int jud(double a, double b){
	if(abs(a) < eps && abs(b) < eps) return 0;
	else if(abs1(a - b) / abs1(a) < eps) return 0;
	if(a < b) return -1;
	return 1;
}
template <typename t> inline int jud(t a, t b){
	if(a < b) return -1;
	if(a == b) return 0;
	return 1;
}

// f_lb == 1��?����ͬ��һ������߽磬f_small == 1��?�����û��Ѱ�ҵ�ֵ����С����
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
	int be = 0, en = na - 1;
	if(*a <= *(a + na - 1)){
		if(f_lb == 0) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != 1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != -1) en = mid;
			else be = mid + 1;
		}
		if(f_small && jud(*(a + be), val) == 1) be--;
		if(!f_small && jud(*(a + be), val) == -1) be++;
	} else {
		if(f_lb) while(be < en){
			int mid = (be + en + 1) / 2;
			if(jud(*(a + mid), val) != -1) be = mid;
			else en = mid - 1;
		}else while(be < en){
			int mid = (be + en) / 2;
			if(jud(*(a + mid), val) != 1) en = mid;
			else be = mid + 1;
		}
		if(!f_small && jud(*(a + be), val) == -1) be--;
		if(f_small && jud(*(a + be), val) == 1) be++;
	}
	return be;
}

template <class T> inline T lowb(T num) {return num & (-num); }
inline int bitnum(ui nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(ull nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitnum(ll nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitmaxl(ui a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(int a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(ull a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
inline int bitmaxl(ll a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }

long long pow(long long n, long long m, long long mod = 0){
	if(m < 0) return 0;
	long long ans = 1;
	long long k = n;
	while(m){
		if(m & 1) {
			ans *= k;
			if(mod) ans %= mod;
		}
		k *= k;
		if(mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

//#define debug
//.........................mi.......feng......xian.......xia.......jin.......zhi.......hack...............................................

const int mod = 1000000007;
const int maxn = 2010;
int n, k;
ll dp[maxn][maxn];

inline void add(ll &a, ll b) {
	a += b;
	if(a >= mod) a -= mod;
}
int main(){
    ios_base::sync_with_stdio(0);
	#ifdef debug //......................................................................................................
	freopen("input.txt", "r", stdin);
	#endif //...........................................................................................................
	dp[0][0] = 1;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) {
		int temp;
		scanf("%d", &temp);
		for(int j = 0; j < 1 << k; j += 2) if(dp[i][j]){
			if(temp != 4) {
				int nxt = min(2 + j, (1 << k));
				add(dp[i + 1][nxt], dp[i][j]);
			}
			if(temp != 2) {
				int nxt = min(4 + j, (1 << k));
				if(j & 2) nxt = 4;
				add(dp[i + 1][nxt], dp[i][j]);
			}
		}
		add(dp[i + 1][1 << k], dp[i][1 << k] * (1 + (temp == 0)) % mod);
	}
	cout << dp[n][1 << k] << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define MAXN 2048

int n,k,A[MAXN];

int dp[MAXN][(1<<11)];

typedef long long ll;

ll pow( ll a , ll b , ll c ){
    ll ans = 1;
    while( b ){
        if( b&1 ) ans = ( ans * a )%c;
        a = ( a*a )%c;
        b >>= 1;
    }
    return ans;
}

int f(int pos,int pile){

    int up = 0,newmask;
    for(int i=k;i>=0;i--)
        if((pile>>i)&1){
            up = (1<<i);
            break;
        }

    if(pos == n){
        return (up == (1<<k));
    }
    /*if(up == (1<<k)){
        int cnt = 0;
        for(int i=pos;i<n;i++)
            if(A[i] == 0)cnt++;
        return pow(2,cnt,MOD);
    }*/
    for(int i=0;i<=k;i++){
            if((pile>>i)&1){
            up = (1<<i);
            break;
        }
    }
    long long ans = (0);

    if(A[pos] != 0){

        if(A[pos] > up)
            newmask = A[pos];
        else
            newmask = pile+A[pos];
        ans = (1LL*ans+1LL*f(pos+1,newmask))%MOD;
    }
    else{
        int mask1,mask2;

        if(up < 2)mask1 = 2;
        else mask1 = pile + 2;
        if(up < 4)mask2 = 4;
        else mask2 = pile+4;
        ans = (1LL*ans+1LL*f(pos+1,mask1) + 1LL*f(pos+1,mask2))%MOD;
    }
    return dp[pos][pile] = ans;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    memset(dp,-1,sizeof(dp));
    cout<<f(0,0)<<"\n";
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MOD 1000000007
#define MAXN 2048

int n,k,A[MAXN];

int dp[MAXN][(1<<11)];

ll pow( ll a , ll b , ll c ){
    ll ans = 1;
    while( b ){
        if( b&1 ) ans = ( ans * a )%c;
        a = ( a*a )%c;
        b >>= 1;
    }
    return ans;
}

int LZ[MAXN];

int f(int pos,int pile){
    int up = 0,newmask;

    up = 31-__builtin_clz(pile);
    up = (1<<up);

    if(pos == n){
        return (up == (1<<k));
    }
    if(up == (1<<k)){
        return pow(2,LZ[pos],MOD);
    }
    up = __builtin_ctz(pile);
    up = (1<<up);

    if(dp[pos][pile] != -1)return dp[pos][pile];

    int ans = 0;
    if(A[pos] != 0){
        if(A[pos] > up)
            newmask = A[pos];
        else
            newmask = pile+A[pos];
        ans = (1LL*ans+1LL*f(pos+1,newmask))%MOD;
    }
    else{
        int mask1,mask2;
        if(up < 2)mask1 = 2;
        else mask1 = pile + 2;
        if(up < 4)mask2 = 4;
        else mask2 = pile+4;
        ans = (1LL*ans+1LL*f(pos+1,mask1) + 1LL*f(pos+1,mask2))%MOD;
    }
    return dp[pos][pile] = ans;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    int cnt = 0;
    for(int i = n-1;i>=0;i--){
        if(A[i] == 0)cnt++;
        LZ[i] = cnt;
    }
    memset(dp,-1,sizeof(dp));
    cout<<f(0,0)<<"\n";
}


#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define MAXN 2048

int n,k,A[MAXN];

int dp[MAXN][(1<<11)];

typedef long long ll;

ll pow( ll a , ll b , ll c ){
    ll ans = 1;
    while( b ){
        if( b&1 ) ans = ( ans * a )%c;
        a = ( a*a )%c;
        b >>= 1;
    }
    return ans;
}

int f(int pos,int pile){

    int up = 0,newmask;
    for(int i=k;i>=0;i--)
        if((pile>>i)&1){
            up = (1<<i);
            break;
        }

    if(pos == n){
        return (up == (1<<k));
    }
    if(up == (1<<k)){
        int cnt = 0;
        for(int i=pos;i<n;i++)
            if(A[i] == 0)cnt++;
        return pow(2,cnt,MOD);
    }
    for(int i=0;i<=k;i++){
            if((pile>>i)&1){
            up = (1<<i);
            break;
        }
    }
    long long ans = (0);

    if(A[pos] != 0){

        if(A[pos] > up)
            newmask = A[pos];
        else
            newmask = pile+A[pos];
        ans = (1LL*ans+1LL*f(pos+1,newmask))%MOD;
    }
    else{
        int mask1,mask2;

        if(up < 2)mask1 = 2;
        else mask1 = pile + 2;
        if(up < 4)mask2 = 4;
        else mask2 = pile+4;
        ans = (1LL*ans+1LL*f(pos+1,mask1) + 1LL*f(pos+1,mask2))%MOD;
    }
    return dp[pos][pile] = ans;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    memset(dp,-1,sizeof(dp));
    cout<<f(0,0)<<"\n";
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MOD 1000000007
#define MAXN 2048

int n,k,A[MAXN];

int dp[MAXN][(1<<11)];

ll pow( ll a , ll b , ll c ){
    ll ans = 1;
    while( b ){
        if( b&1 ) ans = ( ans * a )%c;
        a = ( a*a )%c;
        b >>= 1;
    }
    return ans;
}

int LZ[MAXN];

int f(int pos,int pile){
    int up = 0,newmask;

    up = 31-__builtin_clz(pile);
    up = (1<<up);
    /*for(int i=k;i>=0;i--)
        if((pile>>i)&1){
            up = (1<<i);
            break;
        }*/
    if(pos == n){
        return (up == (1<<k));
    }
    if(up == (1<<k)){
        return pow(2,LZ[pos],MOD);
    }
    up = __builtin_ctz(pile);
    up = (1<<up);
    /*for(int i=0;i<=k;i++){
            if((pile>>i)&1){
            up = (1<<i);
            break;
        }
    }*/
    int ans = 0;
    if(A[pos] != 0){
        if(A[pos] > up)
            newmask = A[pos];
        else
            newmask = pile+A[pos];
        ans = (1LL*ans+1LL*f(pos+1,newmask))%MOD;
    }
    else{
        int mask1,mask2;
        if(up < 2)mask1 = 2;
        else mask1 = pile + 2;
        if(up < 4)mask2 = 4;
        else mask2 = pile+4;
        ans = (1LL*ans+1LL*f(pos+1,mask1) + 1LL*f(pos+1,mask2))%MOD;
    }
    return dp[pos][pile] = ans;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    int cnt = 0;
    for(int i = n-1;i>=0;i--){
        if(A[i] == 0)cnt++;
        LZ[i] = cnt;
    }

    memset(dp,-1,sizeof(dp));
    cout<<f(0,0)<<"\n";
}


#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define MAXN 2048

int n,k,A[MAXN];

long long dp[MAXN][(1<<11)];

typedef long long ll;

ll pow( ll a , ll b , ll c ){
    ll ans = 1;
    while( b ){
        if( b&1 ) ans = ( ans * a )%c;
        a = ( a*a )%c;
        b >>= 1;
    }
    return ans;
}

long long f(int pos,int pile){

    int up = 0,newmask;
    for(int i=k;i>=0;i--)
        if((pile>>i)&1){
            up = (1<<i);
            break;
        }
    //cout<<pos<<" "<<pile<<endl;
    if(pos == n)return (up == (1<<k));
    int cnt = 0;
    if(up == (1<<k)){
        for(int i=pos;i<n;i++){
            if(A[pos] == 0)cnt++;
        }
        return pow(2,cnt,MOD);
    }

    long long ans = 0;

    if(A[pos] != 0){

        if(A[pos] > up)
            newmask = A[pos];
        else
            newmask = pile+A[pos];
        ans = (ans+f(pos+1,newmask))%MOD;
    }
    else{
        int mask1,mask2;
        if(up < 2)mask1 = 2;
        else mask1 = pile + 2;
        if(up < 4)mask2 = 4;
        else mask2 = pile+4;
        ans = (ans+f(pos+1,mask1) + f(pos+1,mask2))%MOD;
    }
    return dp[pos][pile] = ans;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    memset(dp,-1LL,sizeof(dp));
    cout<<f(0,0)<<"\n";
}


#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define MAXN 2048

int n,k,A[MAXN];

long long dp[MAXN][(1<<11)];

typedef long long ll;

ll pow( ll a , ll b , ll c ){
    ll ans = 1;
    while( b ){
        if( b&1 ) ans = ( ans * a )%c;
        a = ( a*a )%c;
        b >>= 1;
    }
    return ans;
}

long long f(int pos,int pile){

    int up = 0,newmask;
    for(int i=k;i>=0;i--)
        if((pile>>i)&1){
            up = (1<<i);
            break;
        }

    if(pos == n){
        return (up == (1<<k));
    }
    if(up == (1<<k)){
        int cnt = 0;
        for(int i=pos;i<n;i++)
            if(A[i] == 0)cnt++;
        return pow(2,cnt,MOD);
    }
    for(int i=0;i<=k;i++){
            if((pile>>i)&1){
            up = (1<<i);
            break;
        }
    }
    long long ans = (0);

    if(A[pos] != 0){

        if(A[pos] > up)
            newmask = A[pos];
        else
            newmask = pile+A[pos];
        ans = (ans+f(pos+1,newmask))%MOD;
    }
    else{
        int mask1,mask2;

        if(up < 2)mask1 = 2;
        else mask1 = pile + 2;
        if(up < 4)mask2 = 4;
        else mask2 = pile+4;
        ans = (ans+f(pos+1,mask1) + f(pos+1,mask2))%MOD;
    }
    return dp[pos][pile] = ans;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    memset(dp,-1LL,sizeof(dp));
    cout<<f(0,0)<<"\n";
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define UP upper_bound
#define LB lower_bound
#define LL long long
#define Pi 3.14159265358
#define si size()
#define en end()
#define be begin()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ii set<int>::iterator
using namespace std;
const LL m7=1000000007;
LL dp[3000][3000];
int a[3000];
LL n, m, k, i, j, J,b,  res;
main(){
       cin>>n;
       cin>>k;dp[0][0]=1;
       for(i=0;i<n;i++)cin>>a[i];
       for(i=0;i<n;i++)
        {
         for(j=0;j<(1<<k);j++)
          for(b=2;b<=4;b+=2)
            if(a[i]==b || a[i]==0){
             J=j;
             if(J&(b-1))J=0;
             J+=b;
             if(J<(1<<k))dp[i+1][J]=(dp[i+1][J]+dp[i][j])%m7;
            }
        }
       res=1;
       for(i=0;i<n;i++)if(a[i]==0)res=(res*2)%m7;
       for(i=0;i<(1<<k);i++){res-=dp[n][i]; if(res<0)res+=m7; }
       cout<<res;//cin>>n;
       }


#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define UP upper_bound
#define LB lower_bound
#define LL long long
#define Pi 3.14159265358
#define si size()
#define en end()
#define be begin()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ii set<int>::iterator
using namespace std;
const LL m7=1000000007;
LL dp[3000][3000];
LL n, m, k, i, j, b, J, res;
main(){
       cin>>n;
       cin>>k;
       for(i=1;i<=n;i++)cin>>a[i];
       for(i=1;i<=n;i++)
        {
         for(j=0;j<(1<<k);j++)
          {
             b=a[i];
             J=j;
             if(J&(b-1))J=0;
             J+=b;
             if(J<(1<<k))dp[i+1][J]=(dp[i+1][J]+dp[i][j])%m7;

          }
        }
       res=1;
       for(i=1;i<=n;i++)if(a[i]==0)res=(res*2)%m7;
       for(i=0;i<(1<<k);i++)res-=dp[n][i];
       cout<<res;
       }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const int mod = 1e9+7;

ll dp[2005][2000];
int n,k,arr[2005];
ll f(int pos,int mask){
  if(dp[pos][mask]!=-1) return dp[pos][mask];
  ll ret=0;
  if(pos==n){
    if((mask>>(k))) return 1;
    else return 0;
  }
  int p,nmask;
  if(arr[pos]!=0){
    if(arr[pos]==4&&(mask&1)) {
       nmask=2;
       if(mask>>k) nmask|=(1<<k);
      ret=f(pos+1,nmask);
    }else{
       p=0,nmask=mask;
      if(arr[pos]==4) p=1;
      while((nmask>>p)&1){
        nmask=nmask^(1<<p);
        p++;
      }
      if(p<=k) nmask|=(1<<p);
      ret=f(pos+1,nmask);
    }
  }else{
    p=0,nmask=mask;
    while((nmask>>p)&1){
      nmask=nmask^(1<<p);
      p++;
    }
    if(p<=k) nmask|=(1<<p);

    ret=f(pos+1,nmask);
//    printf("%d %d %lld\n",pos,mask,ret);
    p=1;nmask=mask;
    if(mask&1){
      nmask=2;
      if(mask>>k) nmask|=(1<<k);

     ret=(ret+f(pos+1,nmask))%mod;
  //   printf("%d %d %lld\n",pos,mask,ret);
    }else{
      while((nmask>>p)&1){
        nmask=nmask^(1<<p);
        p++;
      }
      if(p<=k) nmask|=(1<<p);
      ret=(ret+f(pos+1,nmask))%mod;
  //    printf("%d %d %lld\n",pos,mask,ret);
    }
  }
  //printf("h%d %d %lld\n",pos,mask,ret);
  dp[pos][mask]=ret;
  return ret;
}
int main(){
  scanf("%d %d",&n,&k);
  FILL(dp,-1);
  k--;
  REP(i,n) scanf("%d",&arr[i]);
  printf("%lld\n",f(0,0));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const int mod = 1e9+7;

ll dp[2005][2000];
int n,k,arr[2005];
ll f(int pos,int mask){
  if(dp[pos][mask]!=-1) return dp[pos][mask];

  ll ret=0;
  if(pos==n){
    //printf("%d\n",mask);
    if((mask>>(k))) return 1;
    else return 0;
  }
  int p,nmask;
  if(arr[pos]!=0){
    if(arr[pos]==4&&(mask&1)) {
       nmask=2;
       if(mask>>k) nmask|=(1<<k);
      ret=f(pos+1,nmask);
    }else{
       p=0,nmask=mask;
      if(arr[pos]==4) p=1;
      while((nmask>>p)&1){
        nmask=nmask^(1<<p);
        p++;
      }
      if(p>k) p=k;
      nmask|=(1<<p);

      ret=f(pos+1,nmask);
    }
  }else{
    p=0,nmask=mask;
    while((nmask>>p)&1){
      nmask=nmask^(1<<p);
      p++;
    }
    if(p>k) p=k;
    nmask|=(1<<p);

    ret=f(pos+1,nmask);
//    printf("%d %d %lld\n",pos,mask,ret);
    p=1;nmask=mask;
    if(mask&1){
      nmask=2;
      if(mask>>k) nmask|=(1<<k);

     ret=(ret+f(pos+1,nmask))%mod;
  //   printf("%d %d %lld\n",pos,mask,ret);
    }else{
      while((nmask>>p)&1){
        nmask=nmask^(1<<p);
        p++;
      }
      if(p>k) p=k;
       nmask|=(1<<p);
      ret=(ret+f(pos+1,nmask))%mod;
  //    printf("%d %d %lld\n",pos,mask,ret);
    }
  }
  //printf("h%d %d %lld\n",pos,mask,ret);
  dp[pos][mask]=ret;
  return ret;
}
int main(){
  scanf("%d %d",&n,&k);
  FILL(dp,-1);
  k--;
  REP(i,n) scanf("%d",&arr[i]);
  printf("%lld\n",f(0,0));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const int mod = 1e9+7;

ll dp[2005][4000];
int n,k,arr[2005];
ll f(int pos,int mask){
  if(dp[pos][mask]!=-1) return dp[pos][mask];

  ll ret=0;
  if(pos==n){
    //printf("%d\n",mask);
    if((mask>>(k))) return 1;
    else return 0;
  }
  int p,nmask;
  if(arr[pos]!=0){
    if(arr[pos]==4&&(mask&1)) {
       nmask=2;
       if(mask>>k) nmask|=(1<<k);
      ret=f(pos+1,nmask);
    }else{
       p=0,nmask=mask;
      if(arr[pos]==4) p=1;
      while((nmask>>p)&1){
        nmask=nmask^(1<<p);
        p++;
      }
      if(p>k) p=k;
      nmask|=(1<<p);

      ret=f(pos+1,nmask);
    }
  }else{
    p=0,nmask=mask;
    while((nmask>>p)&1){
      nmask=nmask^(1<<p);
      p++;
    }
    if(p>k) p=k;
    nmask|=(1<<p);

    ret=f(pos+1,nmask);
//    printf("%d %d %lld\n",pos,mask,ret);
    p=1;nmask=mask;
    if(mask&1){
      nmask=2;
      if(mask>>k) nmask|=(1<<k);

     ret=(ret+f(pos+1,nmask))%mod;
  //   printf("%d %d %lld\n",pos,mask,ret);
    }else{
      while((nmask>>p)&1){
        nmask=nmask^(1<<p);
        p++;
      }
      if(p>k) p=k;
       nmask|=(1<<p);
      ret=(ret+f(pos+1,nmask))%mod;
  //    printf("%d %d %lld\n",pos,mask,ret);
    }
  }
  //printf("h%d %d %lld\n",pos,mask,ret);
  dp[pos][mask]=ret;
  return ret;
}
int main(){
  scanf("%d %d",&n,&k);
  FILL(dp,-1);
  k--;
  REP(i,n) scanf("%d",&arr[i]);
  printf("%lld\n",f(0,0));
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0; i<n; ++i)

#define gi(a) scanf("%d",&a)

#define pis(a) printf("%d ",a)
#define pin(a) printf("%d\n",a)

const int max_n=2000+5;
const int max_mask=(1<<11)+5;
const int modref=1000000007;

int n,k;
int a[max_n];
int dp[max_n+1][max_mask+1]={0};

int main()
{
    gi(n); gi(k);

    rep(i,n)
        gi(a[i]);

    dp[0][0]=1;
    int nmask;
    for(int i=0; i<n; ++i)
        for(int mask=0; mask<(1<<k); mask+=2)
            if(dp[i][mask])
            {
                //cout<<i<<" "<<mask<<"\n";

                // place 2
                if(a[i]!=4)
                {
                    int b=1;
                    while(mask&(1<<b)) ++b;

                    nmask=mask&( ((1<<k)-1)^((1<<b)-1) );
                    //cout<<"@@ "<<b<<" "<<mask<<" "<<nmask<<" "<<( ((1^k)-1)^((1^b)-1) )<<"\n";
                    nmask=nmask|(1<<b);
                    //cout<<"@@ "<<b<<" "<<mask<<" "<<nmask<<"\n";

                    dp[i+1][nmask]+=dp[i][mask];
                    dp[i+1][nmask]%=modref;
                }

                //place 4
                if(a[i]!=2)
                {
                    if(mask&2)
                    {
                        nmask=4;

                        dp[i+1][nmask]+=dp[i][mask];
                        dp[i+1][nmask]%=modref;
                    }
                    else
                    {
                        int b=2;
                        while(mask&(1<<b)) ++b;

                        nmask=mask&( ((1^k)-1)^((1^b)-1) );
                        nmask=nmask|(1<<b);

                        dp[i+1][nmask]+=dp[i][mask];
                        dp[i+1][nmask]%=modref;
                    }
                }
            }

    int res=0,dres;
    for(int i=0; i<=n; ++i)
    {
        dres=dp[i][1<<k];
        for(int j=i; j<n; ++j)
            if(a[i]==0)
            {
                dres*=2;
                dres%=modref;
            }
        res+=dres;
        res%=modref;
    }

    pin(res);
}


#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0; i<n; ++i)

#define gi(a) scanf("%d",&a)

#define pis(a) printf("%d ",a)
#define pin(a) printf("%d\n",a)

const int max_n=2000+5;
const int max_mask=(1<<11)+5;
const int modref=1000000007;

int n,k;
int a[max_n];
int dp[max_n+1][max_mask+1]={0};

int main()
{
    gi(n); gi(k);

    rep(i,n)
        gi(a[i]);

    dp[0][0]=1;
    int nmask;
    for(int i=0; i<n; ++i)
        for(int mask=0; mask<(1<<k); mask+=2)
            if(dp[i][mask])
            {
                //cout<<i<<" "<<mask<<": "<<dp[i][mask]<<"\n";

                // place 2
                if(a[i]!=4)
                {
                    int b=1;
                    while(mask&(1<<b)) ++b;

                    nmask=mask&( ((1<<k)-1)^((1<<b)-1) );
                    //cout<<"@@ "<<b<<" "<<mask<<" "<<nmask<<" "<<( ((1^k)-1)^((1^b)-1) )<<"\n";
                    nmask=nmask|(1<<b);
                    //cout<<"@@ "<<b<<" "<<mask<<" "<<nmask<<"\n";

                    dp[i+1][nmask]+=dp[i][mask];
                    dp[i+1][nmask]%=modref;
                }

                //place 4
                if(a[i]!=2)
                {
                    if(mask&2)
                    {
                        nmask=4;

                        dp[i+1][nmask]+=dp[i][mask];
                        dp[i+1][nmask]%=modref;
                    }
                    else
                    {
                        int b=2;
                        while(mask&(1<<b)) ++b;

                        nmask=mask&( ((1<<k)-1)^((1<<b)-1) );
                        nmask=nmask|(1<<b);

                        dp[i+1][nmask]+=dp[i][mask];
                        dp[i+1][nmask]%=modref;
                    }
                }
            }

    int res=0,dres;
    for(int i=0; i<=n; ++i)
    {
        dres=dp[i][1<<k];
        //cout<<"@ "<<i<<": "<<dp[i][1<<k]<<"\n";
        for(int j=i; j<n; ++j)
            if(a[j]==0)
            {
                dres*=2;
                dres%=modref;
            }
        //cout<<dres<<"\n";
        res+=dres;
        res%=modref;
    }

    pin(res);
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <bitset>
#include <set>
#include <algorithm>

using namespace std;

const int maxMask = 1<<13, maxN = 2005;
const long long P = 1000000007LL;

long long f[maxN][maxMask];
int x[maxN];
int n, k;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> x[i];

    f[0][0] = 1LL;

    for (int len = 0; len < n; len++) {
        for (int mask = 0; mask < maxMask; mask++) {
            int nowX = x[len];
            if (nowX==2) {
                f[len + 1][mask + nowX] += f[len][mask];
                f[len + 1][mask + nowX] %= P;
            }
            else if (nowX==4) {
                if ((mask&3)) {
                    f[len + 1][nowX] += f[len][mask];
                    f[len + 1][nowX] %= P;
                }
                else {
                    f[len + 1][mask + nowX] += f[len][mask];
                    f[len + 1][mask + nowX] %= P;
                }
            }
            else {
                nowX = 2;
                f[len + 1][mask + nowX] += f[len][mask];
                f[len + 1][mask + nowX] %= P;
                nowX = 4;
                if (mask%4!=0) {
                    f[len + 1][nowX] += f[len][mask];
                    f[len + 1][nowX] %= P;
                }
                else {
                    f[len + 1][mask + nowX] += f[len][mask];
                    f[len + 1][mask + nowX] %= P;
                }
            }
        }
    }

    long long ans = 0;

    for (int m = 0; m < maxMask; m++)
        if (m>=(1<<k)) ans = (ans + f[n][m]) % P;

    cout << ans << '\n';

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <bitset>
#include <set>
#include <algorithm>

using namespace std;

const int maxMask = 1<<13, maxN = 2005;
const long long P = 1000000007LL;

long long f[maxN][maxMask][2];
int x[maxN];
int n, k;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> n >> k;

    for (int i = 0; i < n; i++)
        cin >> x[i];

    f[0][0][0] = 1LL;

    int k2 = 1<<k;

    for (int len = 0; len < n; len++) {
        for (int mask = 0; mask < maxMask; mask++) {
            int nowX = x[len];
            if (nowX==2) {
                f[len + 1][mask + nowX][(mask+nowX)>=k2] += f[len][mask][0];
                f[len + 1][mask + nowX][(mask+nowX)>=k2] %= P;
                f[len + 1][mask + nowX][1] += f[len][mask][1];
                f[len + 1][mask + nowX][1] %= P;
            }
            else if (nowX==4) {
                if (mask%4!=0) {
                    f[len + 1][nowX][0] += f[len][mask][0];
                    f[len + 1][nowX][0] %= P;
                    f[len + 1][nowX][1] += f[len][mask][1];
                    f[len + 1][nowX][1] %= P;
                }
                else {
                    f[len + 1][mask + nowX][(mask+nowX)>=k2] += f[len][mask][0];
                    f[len + 1][mask + nowX][(mask+nowX)>=k2] %= P;
                    f[len + 1][mask + nowX][1] += f[len][mask][1];
                    f[len + 1][mask + nowX][1] %= P;
                }
            }
            else {
                nowX = 2;
                f[len + 1][mask + nowX][(mask+nowX)>=k2] += f[len][mask][0];
                f[len + 1][mask + nowX][(mask+nowX)>=k2] %= P;
                f[len + 1][mask + nowX][1] += f[len][mask][1];
                f[len + 1][mask + nowX][1] %= P;
                nowX = 4;
                if (mask%4!=0) {
                    f[len + 1][nowX][0] += f[len][mask][0];
                    f[len + 1][nowX][0] %= P;
                    f[len + 1][nowX][1] += f[len][mask][1];
                    f[len + 1][nowX][1] %= P;
                }
                else {
                    f[len + 1][mask + nowX][(mask+nowX)>=k2] += f[len][mask][0];
                    f[len + 1][mask + nowX][(mask+nowX)>=k2] %= P;
                    f[len + 1][mask + nowX][1] += f[len][mask][1];
                    f[len + 1][mask + nowX][1] %= P;
                }
            }
        }
    }

    long long ans = 0;

    for (int m = 0; m < maxMask; m++)
        ans = (ans + f[n][m][1]) % P;

    cout << ans << '\n';

    return 0;
}


#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define N 2050
#define mo 1000000007
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,nn,mm,an;
int f[N][N];
inline void Do(int x,int y) {
	f[i][x]+=y;
	if (f[i][x]>=mo) f[i][x]-=mo;
}
int main() {
	scanf("%d%d",&n,&m);
	nn=(1<<m)-1; mm=(1<<m-1)-1;
	f[0][0]=1;
	For(i,1,n) {
		scanf("%d",&k);
		For(j,0,nn) if (f[i-1][j]) {
			int A=j>>m-1&1,B=j&mm;
			if (!k||k==2) Do(B+1|A<<m-1,f[i-1][j]);
			if (!k||k==4) {
				if (B&1) Do(2|A<<m-1,f[i-1][j]);
				else Do(B+2|A<<m-1,f[i-1][j]);
			}
		}
	}
	For(j,0,nn) if (j>>m-1&1) an=(an+f[n][j])%mo;
	printf("%d\n",an);
	//for(;;);
	return 0;
}


#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define N 2050
#define mo 1000000007
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,nn,mm,an;
int f[N][N];
inline void Do(int x,int y) {
	f[i][x]+=y;
	if (f[i][x]>=mo) f[i][x]-=mo;
}
int main() {
	scanf("%d%d",&n,&m);
	nn=(1<<m)-1; mm=(1<<m-1)-1;
	f[0][0]=1;
	For(i,1,n) {
		scanf("%d",&k);
		For(j,0,nn) if (f[i-1][j]) {
			int A=j>>m-1&1,B=j&mm;
			if (!k||k==2) Do(j+1|A<<m-1,f[i-1][j]);
			if (!k||k==4) {
				if (j&1) Do(2|A<<m-1,f[i-1][j]);
				else Do(j+2|A<<m-1,f[i-1][j]);
			}
		}
	}
	For(j,0,nn) if (j>>m-1&1) an=(an+f[n][j])%mo;
	printf("%d\n",an);
	//for(;;);
	return 0;
}


#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define N 2050
#define mo 1000000007
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,nn,mm,an;
int f[N][N];
inline void Do(int x,int y) {
	f[i][x]+=y;
	if (f[i][x]>=mo) f[i][x]-=mo;
}
int main() {
	scanf("%d%d",&n,&m);
	nn=(1<<m)-1; mm=(1<<m-1)-1;
	f[0][0]=1;
	For(i,1,n) {
		scanf("%d",&k);
		For(j,0,nn) if (f[i-1][j]) {
			int A=j>>m-1&1,B=j&mm;
			if (!k||k==2) Do(j+1|A<<m-1,f[i-1][j]);
			if (!k||k==4) Do((j&nn-1)+2|A<<m-1,f[i-1][j]);
		}
	}
	For(j,0,nn) if (j>>m-1&1) an=(an+f[n][j])%mo;
	printf("%d\n",an);
	//for(;;);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define y1 sdfsdfsdf
#define ll long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(2e5+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,k,dp[(1<<12)][2031],a[N];
int f(int mask,int x){
	if(x == n+1){
		FOR(i,k,11)
			if((mask>>i)&1) return 1;
		return 0;
	}
	int &r = dp[mask][x];
	if(r != -1) return r;
	r=0;
	if(a[x] == 0){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1);
		else r = f(4,x+1);

		r = (r+f(mask + 2 , x+1))%mod;
	}
	else if(a[x] == 4){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1);
		else r = f(4,x+1);
	}
	else
		r = f(mask+2 , x+1);
	return r%=mod;
}
int main(){
	memset(dp,-1,sizeof dp);
	cin >> n >> k;
	FOR(i,1,n) scanf("%d",&a[i]);
	cout << f(0,1) << endl;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define y1 sdfsdfsdf
#define ll long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(2e5+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,k,dp[(1<<12)][2031][3],a[N];
int f(int mask,int x,int y){
	if((mask>>k)&1){
		mask = 0;
		y=1;
	}
	if(x == n+1){
		int ff=0;
		FOR(i,k,11)
			if((mask >> i)&1) ff=1;
		return (ff or y);
	}
	int &r = dp[mask][x][y];
	if(r != -1) return r;

	FOR(i,k,11) if((mask >> i)&1) y=1;
	r=0;

	if(a[x] == 0){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1 , y);
		else r = f(4,x+1 , y);

		r = (r+f(mask + 2 , x+1 , y))%mod;
	}
	else if(a[x] == 4){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1 , y);
		else r = f(4,x+1 , y);
	}
	else
		r = f(mask+2 , x+1 , y);
	return r%=mod;
}
int main(){
	memset(dp,-1,sizeof dp);
	cin >> n >> k;
	FOR(i,1,n) scanf("%d",&a[i]);
	cout << f(0,1,0) << endl;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define y1 sdfsdfsdf
#define ll long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(2e5+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,k,dp[(1<<12)][2031][3],a[N];
int f(int mask,int x,int y){
	if(x == n+1){
		int ff=0;
		FOR(i,k,11)
			if((mask >> i)&1) ff=1;
		return (ff or y);
	}
	int &r = dp[mask][x][y];
	FOR(i,k,11) if((mask >> i)&1) y=1;
	if(r != -1) return r;
	r=0;
	if(a[x] == 0){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1 , y);
		else r = f(4,x+1 , y);

		r = (r+f(mask + 2 , x+1 , y))%mod;
	}
	else if(a[x] == 4){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1 , y);
		else r = f(4,x+1 , y);
	}
	else
		r = f(mask+2 , x+1 , y);
	return r%=mod;
}
int main(){
	memset(dp,-1,sizeof dp);
	cin >> n >> k;
	FOR(i,1,n) scanf("%d",&a[i]);
	cout << f(0,1,0) << endl;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define y1 sdfsdfsdf
#define ll long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(2e5+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,k,dp[(1<<12)][2031][3],a[N];
int f(int mask,int x,int y){
	if(x == n+1){
		int ff=0;
		FOR(i,k,11)
			if((mask >> i)&1) ff=1;
		return (ff or y);
	}
	int &r = dp[mask][x][y];
	if(r != -1) return r;
	FOR(i,k,11) if((mask >> i)&1) y=1;
	r=0;
	if(a[x] == 0){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1 , y);
		else r = f(4,x+1 , y);

		r = (r+f(mask + 2 , x+1 , y))%mod;
	}
	else if(a[x] == 4){
		if(!((mask>>1)&1))
			r = f(mask + 4 , x+1 , y);
		else r = f(4,x+1 , y);
	}
	else
		r = f(mask+2 , x+1 , y);
	return r%=mod;
}
int main(){
	memset(dp,-1,sizeof dp);
	cin >> n >> k;
	FOR(i,1,n) scanf("%d",&a[i]);
	cout << f(0,1,0) << endl;
}


#include<bits/stdc++.h>

using namespace std;
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define FORE(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define type(x) __typeof(x.begin())

#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define y1 sdfsdfsdf
#define ll long long
#define pii pair<int,int>
#define mod 1000000007
#define N (int)(2e5+10)
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endll puts("")
#define endl '\n'
#define inf mod
#define ort ((sol+sag)/2)
int n,k,dp[(1<<12)][2031],a[N];
int f(int mask,int x){
	if(x == n+1){
		FOR(i,k,11)
			if((mask>>i)&1) return 1;
		return 0;
	}
	int &r = dp[mask][x];
	if(r != -1) return r;
	r=0;
	if(a[x] == 0){
		if(mask > 2)
			r = f(mask + 4 , x+1);
		else r = f(4,x+1);

		r = (r+f(mask + 2 , x+1))%mod;
	}
	else if(a[x] == 4){
		if(mask > 2)
			r = f(mask + 4 , x+1);
		else r = f(4,x+1);
	}
	else
		r = f(mask+2 , x+1);
	return r%=mod;
}
int main(){
	memset(dp,-1,sizeof dp);
	cin >> n >> k;
	FOR(i,1,n) scanf("%d",&a[i]);
	cout << f(0,1) << endl;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#define endl '\n'

using namespace std;

#define MP make_pair
#define lli long long int

const int N = (int)(2e5 + 20);
const int INF = (1 << 29);
const lli MODULO = 1000000007;

lli d[2020][(1 << 13)];

lli st;
lli ans = 0;
int a[2020];
int zeros[2020];

int m = 0;

lli binpow(lli a, int n) {
    lli res = 1;
    while(n) {
        if (n&1) res*=a;
        a*=a;
        n >>= 1;
        res %= MODULO;
        a %= MODULO;
    }
    return res;
}

inline void check2(int i, int j) {
    d[i+1][j+1] += d[i][j];
    d[i+1][j+1] %= MODULO;
    //cout << i+1 << ' ' << j+1 << ' ' << d[i+1][j+1] << endl;
    m = max(m, j+1);
}

inline void check4(int i, int j) {
    if ((j & 1) == 0) {
        d[i+1][j+2] += d[i][j];
        d[i+1][j+2] %= MODULO;
        //cout << i+1 << ' ' << j+2 << ' ' << d[i+1][j+2] << endl;
        m = max(m, j+2);
    } else {
        if (j >= st) {
            ans += d[i][j] * binpow(2, zeros[i+1]);
            ans %= MODULO;
        } else {
            d[i+1][2] += d[i][j];
            d[i+1][2] %= MODULO;
            m = max(m, 2);
        }

    }
}

int main() {
ios_base::sync_with_stdio(0);
#ifdef FILE_IO
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    d[0][0] = 1;
    st = (1 << (k-1));
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = n-1; i >= 0; --i) zeros[i] = (a[i] == 0 ? 1 : 0) + zeros[i+1];
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= m; ++j) {
            if (d[i][j]) {
                if (a[i] == 0) {
                    check2(i, j);
                    check4(i, j);
                } else if (a[i] == 2) check2(i, j);
                else check4(i, j);
            }
        }
    }
    for(int i = st; i <= m; ++i)
        ans = (ans + d[n][i]) % MODULO;
    cout << ans;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#define endl '\n'

using namespace std;

#define MP make_pair
#define lli long long int

const int N = (int)(2e5 + 20);
const int INF = (1 << 29);
const lli MODULO = 1000000007;

lli d[2020][(1 << 13)];

lli st;
lli ans = 0;
int a[2020];

int m = 0;

inline void check2(int i, int j) {
    d[i+1][j+1] += d[i][j];
    d[i+1][j+1] %= MODULO;
    //cout << i+1 << ' ' << j+1 << ' ' << d[i+1][j+1] << endl;
    m = max(m, j+1);
}

inline void check4(int i, int j) {
    if ((j & 1) == 0) {
        d[i+1][j+2] += d[i][j];
        d[i+1][j+2] %= MODULO;
        //cout << i+1 << ' ' << j+2 << ' ' << d[i+1][j+2] << endl;
        m = max(m, j+2);
    } else {
        d[i+1][2] += d[i][j];
        d[i+1][2] %= MODULO;
        if (j >= st) ans = (ans + d[i][j]) % MODULO;
        m = max(m, 2);
    }
}

int main() {
ios_base::sync_with_stdio(0);
#ifdef FILE_IO
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    d[0][0] = 1;
    st = (1 << (k-1));
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= m; ++j) {
            if (d[i][j]) {
                if (a[i] == 0) {
                    check2(i, j);
                    check4(i, j);
                } else if (a[i] == 2) check2(i, j);
                else check4(i, j);
            }
        }
    }
    for(int i = st; i <= m; ++i)
        ans = (ans + d[n][i]) % MODULO;
    cout << ans;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#define endl '\n'

using namespace std;

#define MP make_pair
#define lli long long int

const int N = (int)(2e5 + 20);
const int INF = (1 << 29);
const lli MODULO = 1000000007;

lli d[2020][(1 << 13)];

int a[2020];

int m = 0;

inline void check2(int i, int j) {
    d[i+1][j+1] += d[i][j];
    d[i+1][j+1] %= MODULO;
    //cout << i+1 << ' ' << j+1 << ' ' << d[i+1][j+1] << endl;
    m = max(m, j+1);
}

inline void check4(int i, int j) {
    if ((j & 1) == 0) {
        d[i+1][j+2] += d[i][j];
        d[i+1][j+2] %= MODULO;
        //cout << i+1 << ' ' << j+2 << ' ' << d[i+1][j+2] << endl;
        m = max(m, j+2);
    } else {
        d[i+1][2] += d[i][j];
        d[i+1][2] %= MODULO;
        m = max(m, 2);
    }
}

int main() {
ios_base::sync_with_stdio(0);
#ifdef FILE_IO
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    d[0][0] = 1;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= m; ++j) {
            if (d[i][j]) {
                if (a[i] == 0) {
                    check2(i, j);
                    check4(i, j);
                } else if (a[i] == 2) check2(i, j);
                else check4(i, j);
            }
        }
    }
    lli ans = 0;
    lli st = (1 << (k-1));
    for(int i = st; i <= m; ++i)
        ans = (ans + d[n][i]) % MODULO;
    cout << ans;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#define endl '\n'

using namespace std;

#define MP make_pair
#define lli long long int

const int N = (int)(2e5 + 20);
const int INF = (1 << 29);
const lli MODULO = 1000000007;

lli d[2020][(1 << 13)];

lli st;
lli ans = 0;
int a[2020];
int zeros[2020];

int m = 0;

lli binpow(lli a, int n) {
    lli res = 1;
    while(n) {
        if (n&1) res*=a;
        a*=a;
        n >>= 1;
        res %= MODULO;
        a %= MODULO;
    }
    return res;
}

inline void check2(int i, int j) {
    d[i+1][j+1] += d[i][j];
    d[i+1][j+1] %= MODULO;
    //cout << i+1 << ' ' << j+1 << ' ' << d[i+1][j+1] << endl;
    m = max(m, j+1);
}

inline void check4(int i, int j) {
    if ((j & 1) == 0) {
        d[i+1][j+2] += d[i][j];
        d[i+1][j+2] %= MODULO;
        //cout << i+1 << ' ' << j+2 << ' ' << d[i+1][j+2] << endl;
        m = max(m, j+2);
    } else {
        d[i+1][2] += d[i][j];
        d[i+1][2] %= MODULO;
        if (j >= st) {
            ans = d[i][j] * binpow(2, zeros[i+1]);
            ans %= MODULO;
        }
        m = max(m, 2);
    }
}

int main() {
ios_base::sync_with_stdio(0);
#ifdef FILE_IO
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    d[0][0] = 1;
    st = (1 << (k-1));
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = n; i >= 0; --i) zeros[i] = (a[i] == 0 ? 1 : 0) + zeros[i+1];
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= m; ++j) {
            if (d[i][j]) {
                if (a[i] == 0) {
                    check2(i, j);
                    check4(i, j);
                } else if (a[i] == 2) check2(i, j);
                else check4(i, j);
            }
        }
    }
    for(int i = st; i <= m; ++i)
        ans = (ans + d[n][i]) % MODULO;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&-(x))
#define fill(A,B) memset(A,B,sizeof(A))
#define Copy(A,B) memcpy(A,B,sizeof(A))
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define dep(i,B,A) for(int i=B;i>=A;i--)
#define RE(B,A) for(A::iterator it=B.begin();it!=B.end();++it)
#define re(i,A) for(int i=0;i<(int)A;i++)
#define re1(i,A) for(int i=1;i<(int)A;i++)
#define de(i,A) for(int i=A-1;i+1;i--)
#define For(i,A,B) for(int i=A;i<B;i++)
#define foredg(i,A) for(int i=H[A];i;i=e[i].nxt)
#define inf (1<<29)
#define inf64 (1LL<<50)
#define mn 5011
#define Mod (1000000007)
#define eps (1e-9)
#define si(x) ((int)x.size())
#define MAX(A,B) A=max(A,B)
#define MIN(A,B) A=min(A,B)
#define ls (cur<<1)
#define rs (cur<<1|1)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef multiset<pii> Set;

const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int powmod(int a,int b) {int tmp=1;a%=Mod;for(;b;b>>=1){if(b&1)tmp=tmp*a%Mod;a=a*a%Mod;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>inline void R(T &xx){xx=0;char ch=getchar();bool F=0;while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')F=1,ch=getchar();while(ch>='0'&&ch<='9')xx=xx+xx+(xx<<3)+ch-48,ch=getchar();if(F)xx=-xx;}
template<class T>inline void add(int&x,T y){for(x+=y;x>=Mod;x-=Mod);}

int n,k,a[mn],f[mn][2222][2],ans;
int main(){
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
#endif
    R(n);R(k);
    rep(i,1,n)R(a[i]);
    f[0][0][0]=1;
    rep(i,1,n){
        if(a[i]==0||a[i]==2)re(j,2049){
            int p=min(j+2,2048);
            add(f[i][p][1],f[i-1][j][1]);
            add(f[i][p][0],f[i-1][j][0]);
        }
        if(a[i]==0||a[i]==4)re(j,2049){
            int p=min(j+4,2048);
            if(j%4)
                add(f[i][4][j>=(1<<k)],f[i-1][j][0]),
                add(f[i][4][1],f[i-1][j][1]);
            else
                add(f[i][p][0],f[i-1][j][0]),
                add(f[i][p][1],f[i-1][j][1]);
        }
    }
    re(i,2049){
        add(ans,f[n][i][0]);
        if(i>=(1<<k))add(ans,f[n][i][1]);
    }printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&-(x))
#define fill(A,B) memset(A,B,sizeof(A))
#define Copy(A,B) memcpy(A,B,sizeof(A))
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define dep(i,B,A) for(int i=B;i>=A;i--)
#define RE(B,A) for(A::iterator it=B.begin();it!=B.end();++it)
#define re(i,A) for(int i=0;i<(int)A;i++)
#define re1(i,A) for(int i=1;i<(int)A;i++)
#define de(i,A) for(int i=A-1;i+1;i--)
#define For(i,A,B) for(int i=A;i<B;i++)
#define foredg(i,A) for(int i=H[A];i;i=e[i].nxt)
#define inf (1<<29)
#define inf64 (1LL<<50)
#define mn 5011
#define Mod (1000000007)
#define eps (1e-9)
#define si(x) ((int)x.size())
#define MAX(A,B) A=max(A,B)
#define MIN(A,B) A=min(A,B)
#define ls (cur<<1)
#define rs (cur<<1|1)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef multiset<pii> Set;

const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int powmod(int a,int b) {int tmp=1;a%=Mod;for(;b;b>>=1){if(b&1)tmp=tmp*a%Mod;a=a*a%Mod;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>inline void R(T &xx){xx=0;char ch=getchar();bool F=0;while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')F=1,ch=getchar();while(ch>='0'&&ch<='9')xx=xx+xx+(xx<<3)+ch-48,ch=getchar();if(F)xx=-xx;}
template<class T>inline void add(int&x,T y){for(x+=y;x>=Mod;x-=Mod);}

int n,k,a[mn],f[mn][2222][2],ans;
int main(){
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
#endif
    R(n);R(k);
    rep(i,1,n)R(a[i]);
    f[0][0][0]=1;
    rep(i,1,n){
        if(a[i]==0||a[i]==2)re(j,2049){
            int p=min(j+2,2048);
            add(f[i][p][1],f[i-1][j][1]);
            add(f[i][p][0],f[i-1][j][0]);
        }
        if(a[i]==0||a[i]==4)re(j,2049){
            int p=min(j+4,2048);
            if(j%4)
                add(f[i][4][j>=(1<<k)],f[i-1][j][0]),
                add(f[i][4][1],f[i-1][j][1]);
            else
                add(f[i][p][0],f[i-1][j][0]),
                add(f[i][p][1],f[i-1][j][1]);
        }
    }
    re(i,2049){
        add(ans,f[n][i][1]);
        if(i>=(1<<k))add(ans,f[n][i][0]);
    }printf("%d\n",ans);
    return 0;
}


#include <iostream>

#include <cstring>

using namespace std;

#define MOD 1000000007

int N, K;
int A[2004];

int memo[2004][1<<12];
int go(int n, int mask) {
   int win_bit = mask & (1<<K);
   if (n >= N)
      return win_bit ? 1 : 0;
   int& res = memo[n][mask];
   if (res < 0) {
      res = 0;
      if (A[n] == 2) {
         res = go(n+1, ( (mask + 2) | win_bit ) & ((1<<(K+1))-1));
      }
      else if (A[n] == 4) {
         res = go(n+1, ( ((mask & ~2) + 4) | win_bit ) & ((1<<(K+1))-1) );
      }
      else {
         res += go(n+1, ( (mask + 2) | win_bit ) & ((1<<(K+1))-1) );
         res += go(n+1, ( ((mask & ~2) + 4) | win_bit ) & ((1<<(K+1))-1) );
      }
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   cin >> N >> K;
   for (int i = 0; i < N; ++i)
      cin >> A[i];

   memset(memo, -1, sizeof(memo));
   int res = go(0, 0);

   cout << res << endl;

   return 0;
}


#include <iostream>

#include <cstring>

using namespace std;

#define MOD 1000000007

int N, K;
int MASKOFF;
int A[2004];

int memo[2][2004][1<<11];
int go(int n, int mask, bool won) {
   if (n >= N)
      return won ? 1 : 0;
   int& res = memo[won][n][mask];
   if (res < 0) {
      res = 0;
      if (A[n] == 2 || A[n] == 0) {
         res += go( n+1, (mask + 2) & MASKOFF, won || (mask + 2) >= (1<<K) );
         res %= MOD;
      }
      if (A[n] == 4 || A[n] == 0) {
         if (mask & 2)
            res += go( n+1, 4, won );
         else
            res += go( n+1, (mask + 4) & MASKOFF, won || (mask + 4) >= (1<<K) );
         res %= MOD;
      }
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   cin >> N >> K;
   for (int i = 0; i < N; ++i)
      cin >> A[i];

   MASKOFF = (1<<K) - 1;

   memset(memo, -1, sizeof(memo));
   int res = go(0, 0, false);

   cout << res << endl;

   return 0;
}


#include <iostream>

#include <cstring>

using namespace std;

#define MOD 1000000007

int N, K;
int MASKOFF;
int A[2004];

int memo[2][2004][1<<11];
int go(int n, int mask, bool won) {
   if (n >= N)
      return won ? 1 : 0;
   int& res = memo[won][n][mask];
   if (res < 0) {
      res = 0;
      if (A[n] == 2 || A[n] == 0) {
         res += go( n+1, (mask + 2) & MASKOFF, won || (mask + 2) >= (1<<K) );
         res %= MOD;
      }
      if (A[n] == 4 || A[n] == 0) {
         if (mask & 2)
            res += go( n+1, 4 & MASKOFF, won );
         else
            res += go( n+1, (mask + 4) & MASKOFF, won || (mask + 4) >= (1<<K) );
         res %= MOD;
      }
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   cin >> N >> K;
   for (int i = 0; i < N; ++i)
      cin >> A[i];

   MASKOFF = (1<<K) - 1;

   memset(memo, -1, sizeof(memo));
   int res = go(0, 0, false);

   cout << res << endl;

   return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int a[2010],s[2010];
int dp[2010][4010];
const int mod=1000000007;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);

    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        a[i]>>=1;
    }
    for(int i=n-1;i>=0;i--){
        s[i]=s[i+1]+(s[i]==0);
    }
    k--;

    int ret=0;
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<k);j++){
            if(!dp[i][j]){
                continue;
            }
            if(a[j]==1||a[j]==0){
                dp[i+1][j+1]+=dp[i][j];
                dp[i+1][j+1]%=mod;
            }
            if(a[j]==2||a[j]==0){
                if(j&1){
                    dp[i+1][2]+=dp[i][j];
                    dp[i+1][2]%=mod;
                }
                else{
                    dp[i+1][j+2]+=dp[i][j];
                    dp[i+1][j+2]%=mod;
                }
            }
        }
        for(int j=(1<<k);j<=4000;j++){
            ret+=(1LL<<s[i+2])%mod*dp[i+1][j]%mod;
            ret%=mod;
        }
    }
    printf("%d\n",ret);

    return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int a[2010];
int dp[2][13][8001][2];
const int mod=1000000007;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    dp[0][0][0][0]=1;
    for(int i=0;i<n;i++){
        memset(dp[(i&1)^1],0,sizeof(dp[0]));
        for(int j=0;j<=12;j++){
            for(int k=0;k<=8000;k++){
                for(int l=0;l<2;l++){
                    if(!dp[i&1][j][k][l]){
                        continue;
                    }
                    if(a[i]==2||a[i]==0){
                        if(l){
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]%=mod;
                        }
                        else{
                            dp[(i&1)^1][j][k][1]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][j][k][1]%=mod;
                        }
                    }
                    if(a[i]==4||a[i]==0){
                        if(l){
                            dp[(i&1)^1][max(j,2)][4][0]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][max(j,2)][4][0]%=mod;
                        }
                        else{
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]%=mod;
                        }
                    }
                }
            }
        }
    }
    int ret=0;
    for(int j=k;j<=12;j++){
        for(int k=0;k<=8000;k++){
            for(int l=0;l<2;l++){
                ret+=dp[(n&1)][j][k][l];
                ret%=mod;
            }
        }
    }
    printf("%d\n",ret);
    return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int a[2010];
int dp[2][13][8001][2];
const int mod=1000000007;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    dp[0][0][0][0]=1;
    for(int i=0;i<n;i++){
        memset(dp[(i&1)^1],0,sizeof(dp[0]));
        for(int j=0;j<=11;j++){
            for(int k=0;k<=8000;k++){
                for(int l=0;l<2;l++){
                    if(!dp[i&1][j][k][l]){
                        continue;
                    }
                    if(a[i]==2||a[i]==0){
                        if(l){
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]%=mod;
                        }
                        else{
                            dp[(i&1)^1][j][k][1]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][j][k][1]%=mod;
                        }
                    }
                    if(a[i]==4||a[i]==0){
                        if(l){
                            dp[(i&1)^1][max(j,2)][4][0]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][max(j,2)][4][0]%=mod;
                        }
                        else{
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]+=dp[(i&1)][j][k][l];
                            dp[(i&1)^1][max(j,(int)log2(k+4))][k+4][0]%=mod;
                        }
                    }
                }
            }
        }
    }
    int ret=0;
    for(int j=k;j<=12;j++){
        for(int k=0;k<=8000;k++){
            for(int l=0;l<2;l++){
                ret+=dp[(n&1)][j][k][l];
                ret%=mod;
            }
        }
    }
    printf("%d\n",ret);
    return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int a[2010],s[2010];
int dp[2010][4010];
long long p2[2010];
const int mod=1000000007;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);

    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        a[i]>>=1;
    }
    p2[0]=1;
    for(int i=0;i<n;i++){
        p2[i+1]=(p2[i]<<1);
        p2[i+1]%=mod;
    }
    for(int i=n-1;i>=0;i--){
        s[i]=s[i+1]+(a[i]==0);
    }
    k--;

    int ret=0;
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<k);j++){
            if(!dp[i][j]){
                continue;
            }
            if(a[i]==1||a[i]==0){
                dp[i+1][j+1]+=dp[i][j];
                dp[i+1][j+1]%=mod;
            }
            if(a[i]==2||a[i]==0){
                if(j&1){
                    dp[i+1][2]+=dp[i][j];
                    dp[i+1][2]%=mod;
                }
                else{
                    dp[i+1][j+2]+=dp[i][j];
                    dp[i+1][j+2]%=mod;
                }
            }
        }
        for(int j=(1<<k);j<=4000;j++){
            if(!dp[i+1][j]){
                continue;
            }
            ret+=(p2[s[i+1]])%mod*dp[i+1][j]%mod;
            ret%=mod;
        }
    }
    printf("%d\n",ret);

    return 0;
}


/*
Author: 1412kid1412@UESTC
*/

#include <stdexcept>
#include <cstdarg>
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>
#include <locale>
#include <sstream>
#include <set>
#include <list>
#include <bitset>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <string>
#include <utility>
#include <cctype>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <deque>
#include <cstdlib>
#include <stack>
#include <iterator>
#include <functional>
#include <complex>
#include <valarray>
using namespace std;

int a[2010],s[2010];
int dp[2010][4010];
long long p2[2010];
const int mod=1000000007;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);

    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        a[i]>>=1;
    }
    p2[0]=1;
    for(int i=0;i<n;i++){
        p2[i+1]=(p2[i]<<1);
        p2[i+1]%=mod;
    }
    for(int i=n-1;i>=0;i--){
        s[i]=s[i+1]+(s[i]==0);
    }
    k--;

    int ret=0;
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<k);j++){
            if(!dp[i][j]){
                continue;
            }
            if(a[i]==1||a[i]==0){
                dp[i+1][j+1]+=dp[i][j];
                dp[i+1][j+1]%=mod;
            }
            if(a[i]==2||a[i]==0){
                if(j&1){
                    dp[i+1][2]+=dp[i][j];
                    dp[i+1][2]%=mod;
                }
                else{
                    dp[i+1][j+2]+=dp[i][j];
                    dp[i+1][j+2]%=mod;
                }
            }
        }
        for(int j=(1<<k);j<=4000;j++){
            if(!dp[i+1][j]){
                continue;
            }
            ret+=(p2[s[i+1]])%mod*dp[i+1][j]%mod;
            ret%=mod;
        }
    }
    printf("%d\n",ret);

    return 0;
}