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.*; 
import java.math.BigInteger;
import java.text.DecimalFormat;

public class Main{
    final long mod = (int)1e9+7, IINF = (long)1e19;
    final int MAX = (int)2e5+1, MX = (int)1e7+1, INF = (int)1e9, root = 3;
    DecimalFormat df = new DecimalFormat("0.0000000000000");
    double eps = 1e-9, PI = 3.141592653589793238462643383279502884197169399375105820974944;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long[] fact = new long[MAX];
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        for(int i = 1, T= (multipleTC)?ni():1; i<= T; i++)solve(i);
        out.flush();
        out.close();
    }
    
    void solve(int TC) throws Exception{
        int n = ni(), m = ni();
        int[] st = new int[n];
        for(int i = 0; i< n; i++)st[i] = 1-ni();
        int[][] a = new int[n][2];for(int i = 0; i< n; i++)a[i][0] = a[i][1] = -1;
        int[][] cont = new int[m+1][];
        for(int i = 0; i<m; i++){
            cont[i] = new int[ni()];
            for(int j = 0; j< cont[i].length; j++){
                cont[i][j] = ni()-1;
                if(a[cont[i][j]][0]==-1)a[cont[i][j]][0] = i;
                else a[cont[i][j]][1] = i;
            }
        }
        int[][] g[] = new int[m][][], edge = new int[n][2];
        int[] cnt = new int[m];
        for(int i = 0; i< n; i++){
            edge[i] = new int[]{a[i][0], a[i][1], st[i]};
            cnt[edge[i][0]]++;cnt[edge[i][1]]++;
        }
        for(int i = 0; i< m; i++)g[i] = new int[cnt[i]][];
        for(int i = 0; i< n; i++){
            g[edge[i][0]][--cnt[edge[i][0]]] = new int[]{edge[i][1], edge[i][2]};
            g[edge[i][1]][--cnt[edge[i][1]]] = new int[]{edge[i][0], edge[i][2]};
        }
        int[] col = new int[m];
        boolean ans = true;
        for(int i = 0; i< m; i++)if(col[i]==0)ans&=dfs(g,col,i, 1);
        pn((ans)?"YES":"NO");
    }
    
    boolean dfs(int[][][] g,int[] col, int u, int c){
        col[u] = c;
        boolean ans = true;
        for(int[] v:g[u]){
            if(col[v[0]]==0)ans&=dfs(g,col,v[0],(v[1]==0)?c:-c);
            else{
                if(v[1]==0 && col[u]!=col[v[0]])ans = false;
                if(v[1]==1 && col[u]*col[v[0]]!=-1)ans = false;
            }
        }
        return ans;
    }
    
    long phi (long n) {
        long result = n;
        for (long i=2; i*i<=n; ++i)
            if (n % i == 0) {
                while (n % i == 0)n /= i;
                result -= result / i;
            }
        if (n > 1)result -= result / n;
        return result;
    }
    
    int lis(long[] a){
        TreeMap<Long, Integer> map = new TreeMap<>();
        int ans = 0;
        for(int i = 0; i< a.length; i++){
            int l = 0;
            if(map.isEmpty() || map.floorEntry(a[i])==null)l = 1;
            else l = map.floorEntry(a[i]).getValue()+1;
            Map.Entry<Long, Integer> e = null;
            while((e = map.ceilingEntry(a[i])) != null && Integer.compare(e.getValue(),l)<=0)map.remove(e.getKey());
            map.put(a[i], l);
            ans = Math.max(ans,l);
        }
        return ans;
    }
    
    int[] sort(int[] a){
        if(a.length==1)return a;
        int mid = a.length/2;
        int[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));
        for(int i = 0, j = 0, k = 0; i< a.length; i++){
            if(j<b.length && k<c.length){
                if(b[j]<c[k])a[i] = b[j++];
                else a[i] = c[k++];
            }else if(j<b.length)a[i] = b[j++];
            else a[i] = c[k++];
        }
        return a;
    }

    long[] sort(long[] a){
        if(a.length==1)return a;
        int mid = a.length/2;
        long[] b = sort(Arrays.copyOfRange(a,0,mid)), c = sort(Arrays.copyOfRange(a,mid,a.length));
        for(int i = 0, j = 0, k = 0; i< a.length; i++){
            if(j<b.length && k<c.length){
                if(b[j]<c[k])a[i] = b[j++];
                else a[i] = c[k++];
            }else if(j<b.length)a[i] = b[j++];
            else a[i] = c[k++];
        }
        return a;
    }

    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    String nln(){return in.nextLine();}
    int ni(){return Integer.parseInt(in.next());}
    long nl(){return Long.parseLong(in.next());}
    double nd(){return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        String nextLine(){
            String str = "";
            try{    
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }   
            return str;
        }
    }
}   