

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  var S = [0,1];
  for(var i=1;i<N;i++){
    var Ss1=S.map(j => j+"0");
    var Ss2=S.map(j => j+"1");
    var S=[...Ss1,...Ss2];
  }
  var P=input[M+1].split(" ").map(i=>parseInt(i));
  for(var i=0;i<M;i++){
    var tmp=input[i+1].split(" ").map(j => parseInt(j));
    for(var k=S.length-1;k>=0;k--){
      stmp=S[k].split("").map(i => parseInt(i));
      var cnt=0;
    for(var j=tmp[0];j>0;j--){
      if(stmp[tmp[j]-1]==1){
        cnt++;
      }
    }
      if(cnt%2!=P[i]){
        S.splice(k,1);
      }
    }
  }
  var ans=S.length;

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));