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.
//Created by Aminul on 10/4/2019.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class CF776D {
    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt(), m = in.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        ArrayDeque<Integer> g[] = new ArrayDeque[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayDeque<>();
        }
        for (int i = 0; i < m; i++) {
            int x = in.nextInt();
            for (int j = 0; j < x; j++) {
                int u = in.nextInt() - 1;
                g[u].addLast(i);
            }
        }
        boolean ok = true;
        TwoSat sat = new TwoSat(m);
        for (int i = 0; ok && i < n; i++) {
            if (a[i] == 0 && g[i].size() == 0) ok = false;
            else if (a[i] == 0) {
                if (g[i].size() == 1) sat.addForce(g[i].getFirst(), true);
                else if (g[i].size() == 2) {
                    sat.addNand(true, g[i].getFirst(), true, g[i].getLast());
                    sat.addNand(false, g[i].getFirst(), false, g[i].getLast());
                }
            } else {
                if (g[i].size() == 1) sat.addForce(g[i].getFirst(), true);
                else if (g[i].size() == 2) {
                    sat.addNand(true, g[i].getFirst(), false, g[i].getLast());
                    sat.addNand(false, g[i].getFirst(), true, g[i].getLast());
                }
            }
        }

        pw.println(ok && sat.solve() ? "YES" : "NO");

        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class TwoSat {
        int n, s[], c;
        boolean mark[];
        ArrayDeque<Integer> g[];
        Stack<Integer> stack;

        TwoSat(int N) {
            this.n = N;
            s = new int[n * 2];
            mark = new boolean[n * 2];
            stack = new Stack<>();
            g = new ArrayDeque[2 * n];
            for (int i = 0; i < 2 * n; i++) {
                g[i] = new ArrayDeque<>();
            }
        }

        void addImpl(boolean xflag, int x, boolean yflag, int y) {
            x = x * 2 + (xflag ? 1 : 0);
            y = y * 2 + (yflag ? 1 : 0);
            addEdge(x, y);
            addEdge(y ^ 1, x ^ 1);
        }

        void addEdge(int from, int to) {
            g[from].addLast(to);
            stack.add(from);
        }

        void removeLastImpl() {
            g[stack.pop()].removeLast();
            g[stack.pop()].removeLast();
        }

        //# 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 mark[v << 1];
        }

        boolean dfs(int u) {
            if (mark[u ^ 1]) return false;
            if (mark[u]) return true;
            mark[u] = true;
            s[c++] = u;
            for (int i : g[u])
                if (!dfs(i)) return false;
            return true;
        }

        boolean solve() {
            //Arrays.fill(mark, false);
            for (int i = 0; i < 2 * n; i += 2) {
                if (!mark[i] && !mark[i + 1]) {
                    c = 0;
                    if (!dfs(i)) {
                        while (c != 0) mark[s[--c]] = false;
                        if (!dfs(i + 1)) return false;
                    }
                }
            }
            return true;
        }
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }



        public String nextLine() {
            int c = skip();
            StringBuilder sb = new StringBuilder();
            while (!isEndOfLine(c)){
                sb.appendCodePoint(c);
                c = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        public char readChar() {
            return (char) skip();
        }
    }
}