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.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Stack;
import java.util.StringTokenizer;

/**
 * 
 */

/**
 * @author Mohamed Anwar
 *
 */

public class sat_Door_problem {
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = in.nextInt();
		int m = in.nextInt();
		int status_of_door[] = new int[n];
		for (int i = 0; i < n; i++) {
			status_of_door[i] = in.nextInt();
		}
		int keys_door[][] = new int[n][2];
		for (int i = 0; i < m; i++) {
			int num = in.nextInt();
			for (int j = 0; j < num; j++) {
				int door = in.nextInt() - 1;
				if (keys_door[door][0] == 0) {
					keys_door[door][0] = i;
				} else {
					keys_door[door][1] = i;
				}
			}
		}
		int V = 2 * m;
		ArrayList<Integer> adj[] = new ArrayList[V];
		for (int i = 0; i < V; i++) {
			adj[i] = new ArrayList<>();
		}

		for (int i = 0; i < n; i++) {
			int A = keys_door[i][0];
			int B = keys_door[i][1];
			if (status_of_door[i] == 0) {
				adj[comp(A, m)].add(B);
				adj[comp(B, m)].add(A);
				adj[A].add(comp(B, m));
				adj[B].add(comp(A, m));
			} else {
				adj[A].add(B);
				adj[comp(B, m)].add(comp(A, m));
				adj[comp(A, m)].add(comp(B, m));
				adj[B].add(A);
			}
		}

		SCC scc = new SCC(adj, false);
		int component[] = scc.getSCC();
		boolean sat = true;
		for (int i = 0; i < m; i++) {
			sat &= component[i] != component[comp(i, m)];
		}
		out.println(sat ? "YES":"NO");
		out.flush();
		out.close();

	}

	static Scanner in = new Scanner();
	static PrintWriter out = new PrintWriter(System.out);
	/*
	 * static ArrayList<Integer> adjList[]; static int[] dfs_num, dfs_low,
	 * visited, component, rootOfComponent, res; static int dfsNumberCounter,
	 * numSCC; static Stack<Integer> S; static int UNVISITED = 0; static int V;
	 * 
	 * public static void tarjanSCC(int u) { dfs_low[u] = dfs_num[u] =
	 * ++dfsNumberCounter; S.push(u); visited[u] = 1; for (int v : adjList[u]) {
	 * if (dfs_num[v] == UNVISITED) tarjanSCC(v); if (visited[v] == 1)
	 * dfs_low[u] = Math.min(dfs_low[u], dfs_low[v]); }
	 * 
	 * if (dfs_low[u] == dfs_num[u]) { while (true) { int v = S.pop();
	 * visited[v] = UNVISITED; component[v] = numSCC; if (u == v) break; }
	 * rootOfComponent[numSCC] = u; numSCC++; } }
	 * 
	 * public static void tarjanSCC() { dfs_low = new int[V]; dfs_num = new
	 * int[V]; visited = new int[V]; component = new int[V]; res = new int[V];
	 * rootOfComponent = new int[V]; S = new Stack<>(); dfsNumberCounter = 0;
	 * numSCC = 0; for (int i = 0; i < V; ++i) if (dfs_num[i] == UNVISITED)
	 * tarjanSCC(i); }
	 * 
	 * static int NOT(int x) { return x ^ 1; }
	 * 
	 * // acceptable values: (0, 1), (1, 0), (1, 1) static void or(int a, int b)
	 * { adjList[NOT(a)].add(b); adjList[NOT(b)].add(a); }
	 * 
	 * // acceptable values: (0, 1), (1, 0) static void or_but_not_both(int a,
	 * int b) { // CNF: (a v b) & (!a v !b) ==> E.g. can't be true for (1, 1) /
	 * (0, 0) or(a, b); or(NOT(a), NOT(b)); }
	 * 
	 * static void force_value(int i, boolean b) { // because after reversed
	 * toposort, I give true to what comes first if (b) adjList[NOT(i)].add(i);
	 * else adjList[i].add(NOT(i)); }
	 * 
	 * static boolean is_solvable() { boolean is_sat = true; for (int i = 0; i <
	 * V; i += 2) { is_sat &= component[i] != component[NOT(i)]; } return
	 * is_sat; }
	 */
	// Coped
	/*
	 * Kosaraju-Sharir Algorithm
	 * 
	 * Identify sinks (reverse post order in inverse graph) Start normal dfs
	 * from the above order , the resulting components form SCC
	 * 
	 * If you want to use 1 based indexing set onBased flag to true
	 * 
	 */

	static class SCC {

		private ArrayList<Integer>[] invGraph;
		private ArrayDeque<Integer> stack;
		private Iterable<Integer>[] adj;
		private int group[];
		private boolean marked[];
		private int numOfComponents;
		private int st, V;

		@SuppressWarnings("unchecked")
		SCC(Iterable<Integer>[] adj, boolean oneBased) {
			st = oneBased ? 1 : 0;
			V = adj.length - st;
			group = new int[V + st];
			this.adj = adj;
			invGraph = new ArrayList[V + st];
			for (int i = st; i < V + st; i++)
				invGraph[i] = new ArrayList<>();
			for (int i = st; i < V + st; i++)
				for (int j : adj[i])
					invGraph[j].add(i);

			marked = new boolean[V + st];
			stack = new ArrayDeque<>();
			for (int i = st; i < V + st; i++)
				if (!marked[i])
					reversePostOrder(i);

			marked = new boolean[V + st];
			int grp = 0;
			for (int i : stack)
				if (!marked[i])
					dfs(i, grp++);

			numOfComponents = grp;
			stack = null;
		}

		private void reversePostOrder(int u) {
			marked[u] = true;
			for (int v : invGraph[u])
				if (!marked[v])
					reversePostOrder(v);
			stack.push(u);
		}

		private void dfs(int u, int grp) {
			marked[u] = true;
			group[u] = grp;
			for (int v : adj[u])
				if (!marked[v])
					dfs(v, grp);
		}

		public int[] getSCC() {
			return group;
		}

		public int numberOfComponents() {
			return numOfComponents;
		}

		@SuppressWarnings("unchecked")
		public HashSet<Integer>[] getDAG() {
			HashSet<Integer>[] dag = new HashSet[numOfComponents];
			for (int i = 0; i < numOfComponents; i++)
				dag[i] = new HashSet<>();
			for (int i = st; i < V + st; i++)
				for (int v : adj[i])
					if (group[i] != group[v])
						dag[group[i]].add(group[v]);

			return dag;
		}
	}

	static int comp(int x, int N) {
		return x <= N ? x + N : x - N;
	}

	static class Scanner {// Fast I/O
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

	}
}
