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.*;

public class DoorProblem {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        boolean[] open = new boolean[n];
        for(int i = 0; i<n; i++) {
            open[i] = scanner.nextInt() == 1;
        }
        int[] sz= new int[n];
        int[][] switches = new int[2][n];
        for(int i = 0; i < m; i++) {
            int x = scanner.nextInt();
            for(int j = 0; j < x; j++) {
                int ind = scanner.nextInt()-1;
                switches[sz[ind]++][ind] = i;
            }
        }
        TwoSAT sat = new TwoSAT(m);
        for(int i = 0; i < n; i++) {
            //if unlocked then need and of switches
            if (open[i]) {
                sat.setNegXor(switches[0][i], switches[1][i]);
            }
            //if locked then need xor of switches
            else {
                sat.setXor(switches[0][i], switches[1][i]);
            }
        }
        boolean[] assn = new boolean[m];
        if (sat.isSat(assn)) out.println("YES");
        else out.println("NO");
        out.flush();
    }
    static class TwoSAT {
        ArrayList<Integer>[] adj;
        int n;
        private int getIndex(int var, boolean pol) { return 2 * var + (pol ? 0 : 1); }
        public TwoSAT(int n) {
            adj = new ArrayList[2 * n];
            this.n = n;
            for(int i = 0; i < 2*n; i++) {
                adj[i] = new ArrayList<>();
            }
        }
        public void setXor(int var1, int var2) {
            addClause(var1, true, var2, true);
            addClause(var1, false, var2, false);
        }
        public void setNegXor(int var1, int var2) {
            addClause(var1, true, var2, false);
            addClause(var1, false, var2, true);
        }
        public void addClause(int var1, boolean pol1, int var2, boolean pol2) {
            adj[getIndex(var1, !pol1)].add(getIndex(var2, pol2));
            adj[getIndex(var2, !pol2)].add(getIndex(var1, pol1));
        }
        public boolean isSat(boolean[] assn) {
            SCC scc = new SCC(adj);
            int[] map = scc.getSCC();
            for(int i = 0; i < n; i++) {
                if (map[2 * i] == map[2 * i + 1]) return false;
                assn[i] = map[2*i] < map[2 * i + 1];
            }
            return true;
        }
    }
    static class SCC {
        private ArrayList<Integer>[] graph;
        private int[] pre, comp, ll;
        private int cnt = 0, curscc = 0;
        private ArrayDeque<Integer> stack;
        private int n;
        SCC(ArrayList<Integer>[] g) {
            graph= g;
            n = g.length;
            pre = new int[n]; comp = new int[n]; ll = new int[n];
            stack = new ArrayDeque<>();
            Arrays.fill(pre, -1);
            for(int i = 0; i < n; i++) {
                if (pre[i] == -1) dfs(i);
            }
        }
        int[] getSCC() {return comp;}
        private void dfs(int cur) {
            pre[cur] = cnt++;
            ll[cur] = pre[cur];
            stack.push(cur);
            for(int edge: graph[cur]) {
                if (pre[edge] == -1) dfs(edge);
                ll[cur] = Math.min(ll[edge], ll[cur]);
            }
            if (ll[cur] == pre[cur]) {
                while(true) {
                    int v = stack.pop();
                    comp[v] = curscc;
                    ll[cur] = graph.length+1;
                    if (v == cur) break;
                }
                curscc++;
            }
        }
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
