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.*;
import java.util.*;

public class A {
	public static void main (String[] args) { new A(); }

	public A() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt(), m = fs.nextInt();
		int[] state = fs.nextIntArray(n);
		int[][] control = new int[n][2];
		int[] ptr = new int[n];
		for(int i = 0; i < m; i++) {
			int x = fs.nextInt();
			for(int j = 0; j < x; j++) {
				int z = fs.nextInt()-1;
				control[z][ptr[z]++] = i;
			}
		}
		
		TwoSat sat = new TwoSat(m);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 2; j++) {
				int cur = control[i][j];
				int other = control[i][j ^ 1];
				
				int st = state[i] ^ 1;
				if(st == 0) {
					sat.addImpl(true, cur, true, other);
				}
				else {
					sat.addImpl(true, cur, false, other);
				}
				
				st = state[i];
				if(st == 0) {
					sat.addImpl(false, cur, true, other);
				}
				else {
					sat.addImpl(false, cur, false, other);
				}
				
			}
		}
		
		boolean res = sat.solve();
		if(res) out.println("YES");
		else out.println("NO");
		
//		out.println(Arrays.toString(sat.vals));
		
		out.close();
	}
	
	static class TwoSat {
		int n, n2;  byte[] vals, cvals;  SCC scc;

		public TwoSat(int nn) {  n2 = 2 * (n = nn);  scc = new SCC(n2);  vals = new byte[n2];}

		// Example: (true, 0, false, 1) => 0 --> !1
		public void addImpl(boolean va, int a, boolean vb, int b) {
			a <<= 1; b <<= 1;  if (!va) a++;  if (!vb) b++;
			scc.add(a, b);  scc.add(b ^ 1, a ^ 1);
		}

		//# Add (a NAND b)
		public void addNand(boolean va, int a, boolean vb, int b) {
			addImpl(va, a, !vb, b);
		}//$

		//# Add (a OR b)
		public void addOr(boolean va, int a, boolean vb, int b) {
			addImpl(!va, a, vb, b); // ~a -> b
		}//$

		//# Add (a XOR b)
		public void addXor(boolean va, int a, boolean vb, int b) {
			addImpl(!va, a, vb, b); // ~a -> b
			addImpl(va, a, !vb, b); // a -> ~b
		}//$

		//# Forces a to have whatever value va is
		public void addForce(int a, boolean va) {
			addImpl(!va, a, va, a);
		}//$

		// Returns the value of the variable v
		public boolean getVal(int v) {
			return vals[v << 1] == 1;
		}

		public boolean solve() {
			int map[] = scc.go();
			for(int i = 0; i < n; i++) {
				if(map[2*i] == map[2*i+1]) return false;
			}
			for(int i = 0; i < n2; i++) vals[i] = (byte)-1;
			for(int i = 0; i < scc.cs; i++) {
				for(int v : scc.comp[i]) {
					if(vals[v] == -1) {
						vals[v] = 1;
					}
					vals[v^1] = (byte)(vals[v]^1);
				}
			}
			return true;
		}
	}

	static class SCC {
		  ArrayList<Integer>[] adj;
		  ArrayList<Integer>[] comp;
		  int n;
		  int idx, cs;
		  boolean[] u;
		  int[] pre, low, map;
		  ArrayDeque<Integer> s;
		  public SCC(int nn) {
		    adj = new ArrayList[n = nn];
		    for (int curr = 0; curr < n; ++curr)
		      adj[curr] = new ArrayList<>();
		  }
		  void add(int v1, int v2) {
		    adj[v1].add(v2); 
		  }
		  int[] go() {
		  comp = new ArrayList[n];
		    idx = 1; cs = 0;
		    pre = new int[n]; low = new int[n]; map = new int[n];
		    u = new boolean[n];
		    s = new ArrayDeque<Integer>();
		    for (int i = 0; i < n; ++i)
		      if (pre[i] == 0)
		        dfs(i);
		    return map;
		  }

		  void dfs(int v) {
		    pre[v] = low[v] = idx++;
		    s.push(v);
		    u[v] = true;
		    for (int to : adj[v]) {
		      if (pre[to] == 0) {
		        dfs(to);
		        low[v] = Math.min(low[v], low[to]);
		      } else if (u[to]) {
		        low[v] = Math.min(low[v], pre[to]);
		      }
		    }
		    if (low[v] == pre[v]) {
		      int next;
		      comp[cs] = new ArrayList<>();
		      do {
		        next = s.pop();
		        u[next] = false;
		        map[next] = cs;
		        comp[cs].add(next);
		      } while (next != v);
		      cs++;
		    }
		  }

		  //# Make sure to call go() before calling this function.
		  // Function returns a new graph such that all SCCs are
		  // compressed into one node and only the edges connecting
		  // two components are in the new graph.
		  // nodeMapping is an integer array that will store the mapping
		  // for each node in the old graph into the new graph.//$
		  ArrayList[] compressSCC() {
		    ArrayList<Integer>[] g = new ArrayList[cs];
		    for(int i = 0; i < cs; i++) g[i] = new ArrayList<Integer>();
		    int[] added = new int[cs];
		    Arrays.fill(added, -1);
		    for(int i = 0; i < cs; i++) {
		      for(int v : comp[i]) {
		        for(int to : adj[v]) {
		          int mapTo = map[to];
		          if(mapTo != i && added[mapTo] != i) {
		            g[i].add(mapTo);
		            added[mapTo] = i;
		          }
		        }
		      }
		    }
		    return g;
		  }
		}
	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}