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.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

import org.omg.CORBA.TypeCodePackage.BadKind;

	
	
	
	
	public class COVID {
	
		static long mod = (int) 1e9 + 7;
		static PrintWriter pw;
			static int n,m;
			
			static ArrayList<Integer>[] adjList;
		

	static int INF=(int)1e6;
	static int[][] pref;
	public static void setup(int t) {
		adjList=new ArrayList[V];
		for(int i=0;i<adjList.length;i++)
			adjList[i]=new ArrayList<>();
		int[][] hate=new int[n][n];
		for(int i=0;i<n;i++) {
			for(int j=t;j<n-1;j++) {
				hate[i][pref[i][j]]=1;
//				hate[pref[i][j]][i]=1;
			}
		}
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(hate[i][j]==1||hate[j][i]==1) {
					if(p[i]==p[j]) {
						addEdge(i, j+n);
						addEdge(j, i+n);
						addEdge(i+n, j);
						addEdge(j+n, i);
					}else if((p[i]==2&&p[j]==0)||(p[j]==2&&p[i]==0)) {
						int a=i,b=j;
						if(p[j]==2) {
							a^=b;b^=a;a^=b;
						}
						addEdge(a+n, b+n);
						addEdge(b, a);
						
					}else if((p[i]==1&&p[j]==0)||(p[i]==0&&p[j]==1)) {
						int a=i,b=j;
						if(p[j]==1) {
							a^=b;b^=a;a^=b;
						}
						addEdge(b+n, a);
						addEdge(a+n, b);
						
					}else {
						int a=i,b=j;
						if(p[j]==2) {
							a^=b;b^=a;a^=b;
										
						}
						addEdge(a, b+n);
						addEdge(b, a+n);
					}
				}
			}
		}
	}
	
	
	
	public static void addEdge(int i, int j) {
		adjList[i].add(j);
	}
	static int[]p;
	public static boolean is2Sat() {
		tarjanSCC();
		for(int i=0;i<m;i++)
			if(SCCIndex[i]==SCCIndex[i+m])return false;
		return true;
	}
	public static void main(String[] args) throws Exception {
				Scanner sc = new Scanner(System.in);
				PrintWriter pw = new PrintWriter(System.out);
				int n=sc.nextInt();
				 m=sc.nextInt();
				V=2*m;
				adjList=new ArrayList[V];
				for(int i=0;i<adjList.length;i++)
					adjList[i]=new ArrayList<>();
				int[] state=sc.nextIntArr(n);
				ArrayList<Integer>[] arr=new ArrayList[n];
				for(int i=0;i<arr.length;i++)
					arr[i]=new ArrayList<>();
				for(int i=0;i<m;i++) {
					int iterate=sc.nextInt();
					for(int j=0;j<iterate;j++) {
						arr[sc.nextInt()-1].add(i);
					}
					
				}
				for(int i=0;i<n;i++) {
					int a=arr[i].get(0);
					int b=arr[i].get(1);
					if(state[i]==1) {
						adjList[b].add(a);
						adjList[a].add(b);
						adjList[b+m].add(a+m);
						adjList[a+m].add(b+m);
						
					}else {
						adjList[a].add(b+m);
						adjList[b].add(a+m);
						adjList[b+m].add(a);
						adjList[a+m].add(b);
					}
				}
				pw.println(is2Sat()?"YES":"NO");
				pw.flush();
			}
				
	static int V, counter, SCC, dfs_num[], dfs_low[];
	static boolean[] inSCC;
	static Stack<Integer> stack;
	static int[] SCCIndex;// to tell me that the i the node belongs to the kth SCC SCCIndex[i] =k to form DAG
	
	
	static void tarjanSCC()	 	//O(V + E)
	{
		counter=0;SCC=0;
		dfs_low=new int[V];
		dfs_num=new int[V];
		SCCIndex=new int[V];
		stack=new Stack<>();
		inSCC= new boolean[V];
		for(int i = 0; i < V; ++i)
			if(dfs_num[i] == 0)
				tarjanSCC(i);
	}
	
	static void tarjanSCC(int u)
	{
		dfs_num[u] = dfs_low[u] = ++counter;
		stack.push(u);
		
		for(int v: adjList[u])
		{
			if(dfs_num[v] == 0)
				tarjanSCC(v);
			if(!inSCC[v])
				dfs_low[u] = Math.min(dfs_low[u], dfs_low[v]);	
		}
		if(dfs_num[u] == dfs_low[u])
		{
			//SCC found
			SCC++;
			while(true)
			{
				int v = stack.pop();
				SCCIndex[v]=SCC;
				inSCC[v] = true;
				if(v == u)
					break;
			}
		}	
	}	

	
			
			static class longPair implements Comparable<longPair> {
			long x, y;
	
			public longPair(long a, long b) {
				x = a;
				y = b;
			}
	
			public int compareTo(longPair p) {
				return (p.x == x) ? ((p.y == y) ? 0 : (y > p.y) ? 1 : -1) : (x > p.x) ? 1 : -1;
			}
		}
	
	
		static class Pair implements Comparable<Pair> {
			int x;
			int y;
	
			public Pair(int a, int b) {
				this.x = a;
				y = b;
			}
	
	
			public int compareTo(Pair o) {
				return (x == o.x) ? ((y > o.y) ? 1 : (y == o.y) ? 0 : -1) : ((x > o.x) ? 1 : -1);
			}
	
			@Override
	
			public int hashCode() {
				final int prime = 31;
				int result = 1;
				result = prime * result + x;
				result = prime * result + y;
				return result;
			}
	
			@Override
	
			public boolean equals(Object obj) {
				if (this == obj)
					return true;
				if (obj == null)
					return false;
				if (getClass() != obj.getClass())
					return false;
				Pair other = (Pair) obj;
				if (x != other.x)
					return false;
				if (y != other.y)
					return false;
				return true;
			}
	
		}
	
		static class Scanner {
			StringTokenizer st;
			BufferedReader br;
	
			public Scanner(InputStream s) {
				br = new BufferedReader(new InputStreamReader(s));
			}
	
			public Scanner(String s) throws FileNotFoundException {
				br = new BufferedReader(new FileReader(s));
			}
	
			public long[] nextLongArr(int n) throws IOException {
				long[] arr = new long[n];
				for (int i = 0; i < n; i++)
					arr[i] = nextLong();
				return arr;
			}
	
			public int[] nextIntArr(int n) throws IOException {
				int[] arr = new int[n];
				for (int i = 0; i < n; i++)
					arr[i] = nextInt();
				return arr;
			}
	
			public String next() throws IOException {
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(br.readLine(), " ,");
				return st.nextToken();
			}
	
			public int nextInt() throws IOException {
				return Integer.parseInt(next());
			}
	
			public long nextLong() throws IOException {
				return Long.parseLong(next());
			}
	
			public String nextLine() throws IOException {
				return br.readLine();
			}
	
			public double nextDouble() throws IOException {
				String x = next();
				StringBuilder sb = new StringBuilder("0");
				double res = 0, f = 1;
				boolean dec = false, neg = false;
				int start = 0;
				if (x.charAt(0) == '-') {
					neg = true;
					start++;
				}
				for (int i = start; i < x.length(); i++) {
					if (x.charAt(i) == '.') {
						res = Long.parseLong(sb.toString());
						sb = new StringBuilder("0");
						dec = true;
					} else {
						sb.append(x.charAt(i));
						if (dec)
							f *= 10;
					}
					if (sb.length() == 18) {
						res += Long.parseLong(sb.toString()) / f;
						sb = new StringBuilder("0");
					}
				}
				res += Long.parseLong(sb.toString()) / f;
				return res * (neg ? -1 : 1);
			}
	
			public boolean ready() throws IOException {
				return br.ready();
			}
	
		}
	
		public static void shuffle(int[] a) {
			int n = a.length;
			for (int i = 0; i < n; i++) {
				int r = i + (int) (Math.random() * (n - i));
				int tmp = a[i];
				a[i] = a[r];
				a[r] = tmp;
			}
		}
	
	}