Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are m switches. Each switch control doors of some rooms, but each door is controlled by exactly two switches.

You are given the initial configuration of the doors. Toggling any switch, that is, turning it ON when it is OFF, or turning it OFF when it is ON, toggles the condition of the doors that this switch controls. Say, we toggled switch 1, which was connected to room 1, 2 and 3 which were respectively locked, unlocked and unlocked. Then, after toggling the switch, they become unlocked, locked and locked.

You need to tell Sherlock, if there exists a way to unlock all doors at the same time.

Input

First line of input contains two integers n and m (2 ≤ n ≤ 105, 2 ≤ m ≤ 105) — the number of rooms and the number of switches.

Next line contains n space-separated integers r1, r2, ..., rn (0 ≤ ri ≤ 1) which tell the status of room doors. The i-th room is locked if ri = 0, otherwise it is unlocked.

The i-th of next m lines contains an integer xi (0 ≤ xi ≤ n) followed by xi distinct integers separated by space, denoting the number of rooms controlled by the i-th switch followed by the room numbers that this switch controls. It is guaranteed that the room numbers are in the range from 1 to n. It is guaranteed that each door is controlled by exactly two switches.

Output

Output "YES" without quotes, if it is possible to open all doors at the same time, otherwise output "NO" without quotes.

Examples

Input

3 3
1 0 1
2 1 3
2 1 2
2 2 3


Output

NO

Input

3 3
1 0 1
3 1 2 3
1 2
2 1 3


Output

YES

Input

3 3
1 0 1
3 1 2 3
2 1 2
1 3


Output

NO

Note

In the second example input, the initial statuses of the doors are [1, 0, 1] (0 means locked, 1 — unlocked).

After toggling switch 3, we get [0, 0, 0] that means all doors are locked.

Then, after toggling switch 1, we get [1, 1, 1] that means all doors are unlocked.

It can be seen that for the first and for the third example inputs it is not possible to make all doors unlocked.
import java.util.*;
import java.io.*;

public class ProbD {
	public static void main(String[] args) {
		ProbD sol = new ProbD();
		sol.start();
	}

	public void print(Object o){ System.out.print(o); }
	public void println(Object o) { System.out.println(o); }

	public void start(){
		submit();
//		submit_backup1();
//		submit_backup2();
//		test();
	}
	
	class Vertex{
		// a vertex is a switch
		int idx;
		int side;
		HashSet<Vertex> blue, red;
		public Vertex(int i){
			side = 0;
			idx = i;
			blue = new HashSet();
			red = new HashSet();
		}
		public int hashCode() {return idx;}
		public void addBlue(Vertex v){
			blue.add(v);
			v.blue.add(this);
		}
		public void addRed(Vertex v){
			red.add(v);
			v.red.add(this);
		}
		public void removeBlue(Vertex v){
			blue.remove(v);
			v.blue.remove(this);
		}
		public void removeRed(Vertex v){
			red.remove(v);
			v.red.remove(this);
		}
	}
	
	public void test(){
		long ttt = System.currentTimeMillis();
		int n = 20000;
		int m = 100000;
		int[] rooms = new int[n];
		HashMap<Integer, HashSet<Integer>> map = new HashMap();
		int[][] switches = new int[m][];
		for(int i=0;i<m;i++) map.put(i, new HashSet());
		for(int i=0;i<n;i++){
			rooms[i] = (int)(Math.random() * 2);
			int a = (int)(Math.random() * m);
			int b = (int)(Math.random() * m);
			if(b==a){
				if(a==0) b = 1;
				else b = a - 1;
			}
			map.get(a).add(i);
			map.get(b).add(i);
		}
		for(int i=0;i<m;i++){
			HashSet<Integer> set = map.get(i);
			switches[i] = new int[set.size()];
			int j = 0;
			for(Integer k : set) switches[i][j++] = k;
		}
//		print("Data generating time: ");
//		println(System.currentTimeMillis()-ttt);
//		ttt = System.currentTimeMillis();
		System.out.println(canEscape(rooms, switches)?"YES":"NO");
//		print("Solving time: ");
//		println(System.currentTimeMillis()-ttt);
	}
	
	public void submit(){
		try{
			BufferedReader rdr = new BufferedReader(
				new InputStreamReader(System.in)
			);
			String raw = rdr.readLine().trim();
			String[] s = raw.split(" ");
			int n = Integer.parseInt(s[0]);
			int m = Integer.parseInt(s[1]);
			int[] rooms = new int[n];
			s = rdr.readLine().trim().split(" ");
			for(int i=0;i<n;i++) rooms[i] = 1 - Integer.parseInt(s[i]);
			int[][] switches = new int[m][];
			for(int i=0;i<m;i++){
				s = rdr.readLine().trim().split(" ");
				int l = Integer.parseInt(s[0]);
				switches[i] = new int[l];
				for(int j=0;j<l;j++) switches[i][j] = Integer.parseInt(s[j+1]) - 1;
			}
			rdr.close();
			
			if(canEscape(rooms, switches)) System.out.println("YES");
			else System.out.println("NO");
			System.out.flush();
		}
		catch(Exception e){ System.out.println(e); }
	}
	
	public void submit_backup1(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] rooms = new int[n];
		scan.nextLine();
		String[] s = scan.nextLine().trim().split(" ");
		for(int i=0;i<n;i++) rooms[i] = 1 - Integer.parseInt(s[i]);
		int[][] switches = new int[m][];
		for(int i=0;i<m;i++){
			s = scan.nextLine().trim().split(" ");
			int l = Integer.parseInt(s[0]);
			switches[i] = new int[l];
			for(int j=0;j<l;j++) switches[i][j] = Integer.parseInt(s[j+1]) - 1;
		}
		scan.close();
		
		if(canEscape(rooms, switches)) System.out.println("YES");
		else System.out.println("NO");
		System.out.flush();
	}
	
	
	public void submit_backup2(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] rooms = new int[n];
		for(int i=0;i<n;i++) rooms[i] = 1 - scan.nextInt();
		int[][] switches = new int[m][];
		for(int i=0;i<m;i++){
			int l = scan.nextInt();
			switches[i] = new int[l];
			for(int j=0;j<l;j++) switches[i][j] = scan.nextInt() - 1;
		}
		scan.close();
		
		if(canEscape(rooms, switches)) System.out.println("YES");
		else System.out.println("NO");
		System.out.flush();
	}
	
	public boolean canEscape(int[] rooms, int[][] switches){
		int n = rooms.length;
		int m = switches.length;
		int[][] switchNumber = new int[n][2];
			//if switchNumber[i][] = {a, b}, that means the a-th and b-th switches can open door i
		LinkedList<int[]> redEdges = new LinkedList(), blueEdges = new LinkedList();
		for(int i=0;i<n;i++) Arrays.fill(switchNumber[i], -1);
		Vertex[] v = new Vertex[m];
		for(int i=0;i<m;i++) for(int j=0;j<switches[i].length;j++){
			int k = switches[i][j];
			if(switchNumber[k][0]==-1) switchNumber[k][0] = i;
			else switchNumber[k][1] = i;
		}
		for(int i=0;i<m;i++) v[i] = new Vertex(i);
		
		for(int i=0;i<n;i++){
			int j = switchNumber[i][0], k = switchNumber[i][1];
			if(rooms[i]==1){ //add red edge(j, k);
				if(v[j].blue.contains(v[k])) return false;
				v[j].addRed(v[k]);
				redEdges.add(new int[] {j, k});
			}
			else{ // add blue edge(j, k);
				if(v[j].red.contains(v[k])) return false;
				v[j].addBlue(v[k]);
				blueEdges.add(new int[] {j, k});
			}
		}
//		boolean ret1 = isPerfectBypartiteGraph(v, redEdges, blueEdges);
//		boolean ret2 = isPerfectBypartiteGraph_backup1(v);
//		if(ret1!=ret2) {
//			println(" ");
//			println("Wrong");
//			for(int i : rooms) print(i+" ");
//			println(" ");
//			for(int[] ss : switches){
//				print("[ ");
//				for(int i : ss) print(i+" ");
//				println("]");
//			}
//			/*
//			*/
//		}
		return isPerfectBypartiteGraph(v, redEdges, blueEdges);
		//bypartite, so that red is in between, blue is inside each part
	}
	
/* Test cases:

3 3
1 0 1
2 1 2
2 1 3
2 2 3

*/
	static long ttttt;
	static long scount;
	private void ptime(){
		print("Time elapsed: ");
		println(System.currentTimeMillis()-ProbD.ttttt);
		ProbD.ttttt = System.currentTimeMillis();
	}
	
	public boolean isPerfectBypartiteGraph(
		Vertex[] vertices, LinkedList<int[]> redEdges, LinkedList<int[]> blueEdges
	){
		//if there is a way to by-partite,
		//so that blue edges are inside each part
		//and red edges are in between
		//then return true;
		//otherwise return false.
		HashSet<Vertex> pool = new HashSet();
		HashSet<Vertex> side1 = new HashSet();
		HashSet<Vertex> side2 = new HashSet();
		Stack<Vertex> leftbag = new Stack();
		Stack<Vertex> rightbag = new Stack();
		for(Vertex v : vertices) pool.add(v);
		for(Vertex cur : pool){
			if(cur.side!=0) continue;
			cur.side = 1;
			leftbag.push(cur);
			while(leftbag.size()>0 || rightbag.size()>0){
				while(leftbag.size()>0){
					Vertex v1 = leftbag.pop();
					for(Vertex v2 : v1.blue){
						if(v2.side==2) return false;
						if(v2.side==0){
							v2.side = 1;
							leftbag.push(v2);
						}
					}
					for(Vertex v2 : v1.red){
						if(v2.side==1) return false;
						if(v2.side==0){
							v2.side = 2;
							rightbag.push(v2);
						}
					}
				}
				while(rightbag.size()>0){
					Vertex v1 = rightbag.pop();
					for(Vertex v2 : v1.red){
						if(v2.side==2) return false;
						if(v2.side==0){
							v2.side = 1;
							leftbag.push(v2);
						}
					}
					for(Vertex v2 : v1.blue){
						if(v2.side==1) return false;
						if(v2.side==0){
							v2.side = 2;
							rightbag.push(v2);
						}
					}
				}
			}
		}
//		println("Checking "+pool.size());
//		for(Vertex v : pool){
//			println(v.idx+" "+v.side);
//		}
		return true;
	}
	
	public boolean isPerfectBypartiteGraph_backup1(Vertex[] vertices){
		//if there is a way to by-partite,
		//so that blue edges are inside each part
		//and red edges are in between
		//then return true;
		//otherwise return false.
		scount = 0;
		ProbD.ttttt = System.currentTimeMillis();
		long poolsize = 0;
		HashSet<Vertex> side1 = new HashSet(), side2 = new HashSet();
		HashSet<Vertex> pool = new HashSet();
		for(Vertex v : vertices) pool.add(v);
		ptime();
		poolsize = pool.size();
		while(pool.size()>0){
//			if(poolsize>pool.size()+5000){
//				print("pool size: ");
//				println(pool.size());
//				println("and scount="+scount);
//				ptime();
//				poolsize = pool.size();
//			}
			LinkedList<Vertex> leftbag = new LinkedList();
			LinkedList<Vertex> rightbag = new LinkedList();
			Vertex cur = null;
			for(Vertex tmp : pool){
				cur = tmp;
				break;
			}
			pool.remove(cur);
			side1.add(cur);
			leftbag.add(cur);
			while(leftbag.size()>0 || rightbag.size()>0){
				HashSet<Vertex> tmp;
				if(leftbag.size()>0){
					Vertex v1 = leftbag.removeFirst();
					tmp = new HashSet();
					for(Vertex v2 : v1.blue){
//						scount ++;
						if(side2.contains(v2)) return false;
						if(side1.contains(v2)) continue;
						tmp.add(v2);
						side1.add(v2);
						leftbag.add(v2);
						pool.remove(v2);
					}
					for(Vertex v2 : tmp) v1.removeBlue(v2);
					tmp = new HashSet();
					for(Vertex v2 : v1.red){
//						scount ++;
						if(side1.contains(v2)) return false;
						if(side2.contains(v2)) continue;
						tmp.add(v2);
						side2.add(v2);
						rightbag.add(v2);
						pool.remove(v2);
					}
					for(Vertex v2 : tmp) v1.removeRed(v2);
				}
				else{
					Vertex v1 = rightbag.removeFirst();
					tmp = new HashSet();
					for(Vertex v2 : v1.blue){
//						scount ++;
						if(side1.contains(v2)) return false;
						if(side2.contains(v2)) continue;
						tmp.add(v2);
						side2.add(v2);
						rightbag.add(v2);
						pool.remove(v2);
					}
					for(Vertex v2 : tmp) v1.removeBlue(v2);
					tmp = new HashSet();
					for(Vertex v2 : v1.red){
//						scount ++;
						if(side2.contains(v2)) return false;
						if(side1.contains(v2)) continue;
						tmp.add(v2);
						side1.add(v2);
						leftbag.add(v2);
						pool.remove(v2);
					}
					for(Vertex v2 : tmp) v1.removeRed(v2);
				}
			}
		}
//		println("scount="+scount);
		return true;
	}
	
	public boolean isPerfectBypartiteGraph_backup2(Vertex[] vertices){
		//if there is a way to by-partite,
		//so that blue edges are inside each part
		//and red edges are in between
		//then return true;
		//otherwise return false.
		HashSet<Vertex> side1 = new HashSet(), side2 = new HashSet();
		LinkedList<Vertex> pool = new LinkedList();
		for(Vertex v : vertices) pool.add(v);
		while(pool.size()>0){
			LinkedList<Vertex> leftbag = new LinkedList();
			LinkedList<Vertex> rightbag = new LinkedList();
			Vertex cur = pool.removeFirst();
			side1.add(cur);
			leftbag.add(cur);
			while(leftbag.size()>0 || rightbag.size()>0){
				if(leftbag.size()>0){
					Vertex v1 = leftbag.removeFirst();
					for(Vertex v2 : v1.blue){
						if(side2.contains(v2)) return false;
						if(side1.contains(v2)) continue;
						side1.add(v2);
						leftbag.add(v2);
						pool.remove(v2);
					}
					for(Vertex v2 : v1.red){
						if(side1.contains(v2)) return false;
						if(side2.contains(v2)) continue;
						side2.add(v2);
						rightbag.add(v2);
						pool.remove(v2);
					}
				}
				else{
					Vertex v1 = rightbag.removeFirst();
					for(Vertex v2 : v1.blue){
						if(side1.contains(v2)) return false;
						if(side2.contains(v2)) continue;
						side2.add(v2);
						rightbag.add(v2);
						pool.remove(v2);
					}
					for(Vertex v2 : v1.red){
						if(side2.contains(v2)) return false;
						if(side1.contains(v2)) continue;
						side1.add(v2);
						leftbag.add(v2);
						pool.remove(v2);
					}
				}
			}
		}
		
		return true;
	}
}