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.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.*;

public class D {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner sc = new FastScanner();

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] unlocked = sc.readIntArray(n);
        int[][] switches = new int[n][];
        for (int i = 0; i < m; i++) {
            int size = sc.nextInt();
            for (int j = 0; j < size; j++) {
                int door = sc.nextInt() - 1;
                if (switches[door] == null) {
                    switches[door] = new int[2];
                    switches[door][0] = i;
                } else {
                    switches[door][1] = i;
                }
            }
        }

        TwoSAT twoSAT = new TwoSAT(m);
        for (int i = 0; i < n; i++) {
            if (unlocked[i] == 1) {
                twoSAT.setXnor(switches[i][0], switches[i][1]);
            } else {
                twoSAT.setXor(switches[i][0], switches[i][1]);
            }
        }

        boolean ok = twoSAT.isSatisfiable();
        if (ok) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    /**
     * Simple TwoSAT solver.  Needs Tarjan's SCC.
     *
     * @author: godmar@gmail.com
     */
    static class TwoSAT {
        List<Integer>[] adj;    // implication graph, size 2*N

        int N;
    /* N variables, 2*N nodes to represent var[i] and !var[i]
     * following http://codeforces.com/blog/entry/16205 we represent
     * X[i] at 2*i and !X[i] at 2*i+1
     *
     * Convention: polarity 'true' means the var. polarity 'false' means !var.
     */

        private int getindex(int var, boolean polarity) {
            return 2*var + (polarity ? 0 : 1);
        }

        @SuppressWarnings("unchecked")
        public TwoSAT(int N) {
            this.N = N;
            adj = new List[2*N];
            for (int i = 0; i < 2*N; i++)
                adj[i] = new ArrayList<Integer>();
        }

        /* var1 xor var2 means var1 || var2 && !var || !var2 */
        void setXor(int var1, int var2) {
            addClause(var1, true, var2, true);
            addClause(var1, false, var2, false);
        }

        void setXnor(int var1, int var2) {
            addClause(var1, false, var2, true);
            addClause(var1, true, var2, false);
        }

        /* var1 || var2 */
        void setOr(int var1, int var2) {
            addClause(var1, true, var2, true);
        }

        /*
         * Record a clause 'var1' || 'var2', optionally !var1 or !var2
         *
         * Since x || y == (!x -> y) && (!y -> x), we must add two edges
         * to the implication graph.
         *
         * Note: for usability, we set the boolean such that passing true
         * means the actual value, and passing false means the negated value.
         *
         * Pass 'polarity' to be true if you mean 'var'
         * Pass 'polarity' to be false if you mean '!var'
         */
        void addClause(int var1, boolean polarity1, int var2, boolean polarity2) {
            // !var1 -> var2
            adj[getindex(var1, !polarity1)].add(getindex(var2, polarity2));
            // !var2 -> var1
            adj[getindex(var2, !polarity2)].add(getindex(var1, polarity1));
        }

        /* Fix a variable by adding an implication connecting either
         * !X -> X or X -> !X for true and false, resp. */
        void set(int var, boolean value) {
            adj[getindex(var, !value)].add(getindex(var, value));
        }

        /* Setting a variable to true is saying that !var -> var */
        void setTrue(int var) {
            set(var, true);
        }

        /* Setting a variable to false is saying that var -> !var */
        void setFalse(int var) {
            set(var, false);
        }

        /* Undo the last fixed value assigment for variable var or !var.
         * This is useful if you need to set a variable to true/false, test
         * satisfiability, and then undo the setting.
         * Added for WF/2009/Minister's Mess.
         */
        void removeLastFixedAssignment(int var, boolean value) {
            int i = getindex(var, !value);
            adj[i].remove(adj[i].size()-1);
        }

        /*
         * Determine satisfiability: if any x and !x are in the same SCC,
         * the answer is false - why?  Because x -> !x && !x -> x is a contradiction.
         */
        boolean isSatisfiable() {
            SCC scc = new SCC(adj);
            for (int i = 0; i < N; i++) {
                if (scc.stronglyConnected(2*i, 2*i + 1))
                    return false;
            }
            return true;
        }

        /**
         * Determine satisfiability and return an assignment if satisfiable.
         * See Aspvall, Plass, and Tarjan, IPL Vol 8(3) 1979
         * A Linear-Time Algorithm for Testing the Truth of Certain
         * Quantified Boolean Formulas.
         */
        @SuppressWarnings("unchecked")
        boolean isSatisfiable(boolean [] vassn) {
            SCC scc = new SCC(adj);
            int nS = scc.count();
            // compute dual components
            int [] dual = new int[nS];     // Scomp
            for (int i = 0; i < 2*N; i += 2) {
                dual[scc.id(i)] = scc.id(i^1);
                dual[scc.id(i^1)] = scc.id(i);
            }

            Boolean [] assn = new Boolean[nS];
            for (int S = 0; S < nS; S++) {
                if (assn[S] == null) {
                    assn[S] = Boolean.TRUE;
                    if (S == dual[S])
                        return false;

                    assn[dual[S]] = Boolean.FALSE;
                }
            }
            for (int i = 0; i < N; i++)
                vassn[i] = assn[scc.id(2*i)];
            return true;
        }
    }

    public static class SCC {

        private boolean[] marked;        // marked[v] = has v been visited?
        private int[] id;                // id[v] = id of strong component containing v
        private int[] low;               // low[v] = low number of v
        private int pre;                 // preorder number counter
        private int count;               // number of strongly-connected components
        private Stack<Integer> stack;
        private int[] sccsize;           // size of scc[i], only if desired
        private List<Integer> [] G;      // store underlying graph, only needed for reduce

        public SCC(List<Integer> [] G) {
            this.G = G;
            marked = new boolean[G.length];
            stack = new Stack<Integer>();
            id = new int[G.length];
            low = new int[G.length];
            sccsize = new int[G.length];
            for (int v = 0; v < G.length; v++) {
                if (!marked[v]) dfs(G, v);
            }
        }

        private void dfs(List<Integer> [] G, int v) {
            marked[v] = true;
            low[v] = pre++;
            int min = low[v];
            stack.push(v);
            for (int w : G[v]) {
                if (!marked[w]) dfs(G, w);
                if (low[w] < min) min = low[w];
            }
            if (min < low[v]) { low[v] = min; return; }
            int w;
            do {
                w = stack.pop();
                id[w] = count;
                sccsize[count]++;
                low[w] = G.length;
            } while (w != v);
            count++;
        }

        // return the number of strongly connected components
        public int count() { return count; }

        // are v and w strongly connected?
        public boolean stronglyConnected(int v, int w) {
            return id[v] == id[w];
        }

        // in which strongly connected component is vertex v?
        public int id(int v) { return id[v]; }

        // how big is the strongly connected component with number #x
        // assert 0 <= x < count
        public int sccsize(int x) { return sccsize[x]; }

        /*
         * Return reduced acyclic graph in which all SCC are collapsed into one node
         */
        @SuppressWarnings("unchecked")
        public List<Integer> [] reduce() {
            Set<Integer> [] set = new Set[count];
            for (int i = 0; i < count; i++)
                set[i] = new HashSet<>();

            for (int i = 0; i < G.length; i++)
                for (Integer j : G[i])
                    if (!stronglyConnected(i, j))
                        set[id[i]].add(id[j]);

            List<Integer> [] r = new List[count];
            for (int i = 0; i < count; i++)
                r[i] = new ArrayList<>(set[i]);

            return r;
        }
    }


    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;
        }
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextLong();
            }
            return a;
        }
    }
}
