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 Main{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
          int R[],pa[];
          void find(int u){
           if(pa[u]==u)return;
           find(pa[u]);pa[u]=pa[pa[u]];
          }
          void merge(int u,int v){
           find(u);find(v);
           if(pa[u]==pa[v])return;
           if(R[pa[u]]==R[pa[v]])++R[pa[u]];
           if(R[pa[u]]<R[pa[v]])pa[pa[u]]=pa[v];
           else pa[pa[v]]=pa[u];
          }
          public void solve(int testNumber, InputReader in, PrintWriter out) {
              int n=in.nextInt(),m=in.nextInt();
              int a[]=new int[n+1];
              for(int i=1;i<=n;i++)a[i]=in.nextInt();
              ArrayList<Integer> al[]=new ArrayList[n+1];
              for(int i=1;i<=n;i++)al[i]=new ArrayList<>();
              for(int i=1;i<=m;i++){
               int no=in.nextInt();
               for(int j=0;j<no;j++)al[in.nextInt()].add(i);
              }
              R=new int[2*m+1];pa=new int[2*m+1];
              for(int i=1;i<=2*m;i++)pa[i]=i;
              for(int i=1;i<=n;i++){
               find(al[i].get(0));find(m+al[i].get(0));
               find(al[i].get(1));find(m+al[i].get(1));
               if(a[i]==0){
                merge(al[i].get(0),m+al[i].get(1));
                merge(m+al[i].get(0),al[i].get(1));
               }else{
                merge(al[i].get(0),al[i].get(1));
                merge(m+al[i].get(0),m+al[i].get(1));
               }
              }
              for(int i=1;i<=2*m;i++){
                find(i);
               }                                          
               for(int i=1;i<=m;i++){
                if(pa[i]==pa[i+m]){
                 out.print("NO");return;
                }
               }out.print("YES");
          }
          
//        pair[] radixSort(pair[] f){ return radixSort(f, f.length); }
//	pair[] radixSort(pair[] f, int n)
//	{
//		pair[] to = new pair[n];
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i].v&0xffff)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++){
//                         to[b[f[i].v&0xffff]++] = f[i];
//                        }
//			pair[] d = f; f = to;to = d;
//		}
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i].v>>>16)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++)to[b[f[i].v>>>16]++] = f[i];
//			pair[] d = f; f = to;to = d;
//		}
//		return f;
//	}
//        
//        private static final int B1 = 31;
//	private static final int M1 = 1000000007;
//	private static final int Z1 = 16983;
//	private static final int B2 = 37;
//	private static final int M2 = 1000000009;
//	private static final int Z2 = 18657;
//	
//	public static long unrootedHash(int[][] g)
//	{
//		int[] cs = center(g);
//		long[] lhs = new long[cs.length];
//		int p = 0;
//		for(int c : cs){
//			lhs[p++] = rootedHash(c, -1, g);
//		}
//		Arrays.sort(lhs);
//		long hl = Z1, hr = Z2;
//		for(long lh : lhs){
//			long lhl = lh>>>32, lhr = (int)lh;
//			hl = (hl * B1 + lhl*lhl) % M1;
//			hr = (hr * B2 + lhr*lhr) % M2;
//		}
//		return hl<<32|hr;
//	}
//	
//	public static long rootedHash(int cur, int pre, int[][] g)
//	{
//		long[] hs = new long[g[cur].length];
//		int p = 0;
//		for(int e : g[cur]){
//			if(e != pre){
//				hs[p++] = rootedHash(e, cur, g);
//			}
//		}
//		Arrays.sort(hs, 0, p);
//		long hl = Z1, hr = Z2;
//		for(int i = 0;i < p;i++){
//			hl = (hl * B1 + hs[i]*hs[i]) % M1;
//			hr = (hr * B2 + hs[i]*hs[i]) % M2;
//		}
//		return hl<<32|hr;
//	}
	
       }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}