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.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

// ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
// The Door Problem
public class Problem_776_D {
    FastScanner scanner;
    PrintWriter out;
    
    
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        Problem_776_D solver = new Problem_776_D();
        solver.solve(1, new InputStreamReader(inputStream), out);
        out.close();
    }

    void solve(int test, Reader in, PrintWriter out) {
        this.scanner = new FastScanner(in);
        this.out = out;
        int nDoors = rint();
        int nSwitches = rint();
        int[] r = rarr(nDoors);
        int[][] a = new int[nSwitches][];
        for (int i = 0; i < nSwitches; i++) {
            int k = rint();
            a[i] = rarr(k);
        }
        
        Graph g = new Graph(nSwitches + 1);
        int[] d2s = new int[nDoors + 1];
        for (int i = 0; i < nSwitches; i++) {
            for (int j = 0; j < a[i].length; j++) {
                int d = a[i][j];
                if (d2s[d] == 0) {
                    d2s[d] = i + 1;
                } else {
                    g.addEdge(new EdgeDoor(d2s[d], i+1, r[d-1] == 1));
                }
            }
        }
//        System.out.println(g);
        
        String ans = "YES";
        boolean[] visited1 = new boolean[nSwitches + 1];
        boolean[] visited2 = new boolean[nSwitches + 1];
        boolean[] switches1 = new boolean[nSwitches + 1];
        boolean[] switches2 = new boolean[nSwitches + 1];
        for (int s = 1; s < nSwitches + 1; s++) {
            if (!visited1[s]) {
                switches1[s] = false;
                switches2[s] = true;
                if (!bfs(s, g, switches1, visited1) && !bfs(s, g, switches2, visited2)) {
                    ans = "NO";
                    break;
                }
            }
        }
        sout(ans);
    }
    
    boolean bfs(int s, Graph g, boolean[] switches, boolean[] visited) {
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(s);
        visited[s] = true;
        while (!queue.isEmpty()) {
            Integer v = queue.poll();
            for (Graph.Edge e : g.edges(v)) {
                int w = e.other(v);
                EdgeDoor edge = (EdgeDoor) e;
                if (visited[w]) {
                    boolean ok;
                    if (edge.isOpen()) {
                        ok = switches[w] == switches[v];
                    } else {
                        ok = switches[w] != switches[v];
                    }
                    if (!ok) {
                        return false;
                    }
                } else {
                    if (edge.isOpen()) {
                        switches[w] = switches[v];
                    } else {
                        switches[w] = !switches[v];
                    }
                    queue.add(w);
                    visited[w] = true;
                }
            }
        }
        return true;
    }
    
    static class EdgeDoor extends Graph.EdgeImpl {
        private final boolean open;

        EdgeDoor(int v, int w, boolean open) {
            super(v, w);
            this.open = open;
        }

        public boolean isOpen() {
            return open;
        }
    }
    
    static class Graph {
        private final int n;
        private int m;
        private Set<Edge>[] adj;
        
        /**
         * Initializes an empty graph with {@code n} vertices and 0 edges.
         */
        @SuppressWarnings("unchecked")
        public Graph(int n) {
            if (n < 0)
                throw new IllegalArgumentException("Number of vertices must be nonnegative");
            this.n = n;
            this.m = 0;
            adj = (Set<Edge>[]) new HashSet[n];
            for (int v = 0; v < n; v++) {
                adj[v] = new HashSet<>();
            }
        }

        /**
         * Returns the number of vertices in this graph.
         */
        public int n() {
            return n;
        }

        /**
         * Returns the number of edges in this graph.
         */
        public int m() {
            return m;
        }

        private void validateVertex(int i) {
            if (i < 0 || i >= n)
                throw new IllegalArgumentException("vertex " + i + " is not between 0 and " + (n-1));
        }
        
        /**
         * Undirected edge
         */
        interface Edge {
            int either();
            int other(int vertex);
        }

        static class EdgeImpl implements Edge {
            private final int v;
            private final int w;
            
            EdgeImpl(int v, int w) {
                if ( v <= w) {
                    this.v = v;
                    this.w = w;
                } else {
                    this.v = w;
                    this.w = v;
                }
            }
            
            @Override
            public int either() {
                return v;
            }
            
            @Override
            public int other(int vertex) {
                if (vertex == v) 
                    return w;
                else if (vertex == w) 
                    return v;
                else 
                    throw new IllegalArgumentException("Illegal endpoint");
            }
        }
        
        /**
         * Adds the undirected edge v-w to this graph.
         */
        public void addEdge(Edge e) {
            int v = e.either();
            int w = e.other(v);
            validateVertex(v);
            validateVertex(w);
            m++;
            adj[v].add(e);
            adj[w].add(e);
        }

        /**
         * Returns the vertices adjacent to vertex {@code v}.
         */
        public Iterable<Integer> adj(int v) {
            validateVertex(v);
            Iterator<Edge> edgeIter = adj[v].iterator();
            return () -> new Iterator<Integer>() {
                @Override
                public boolean hasNext() {
                    return edgeIter.hasNext();
                }

                @Override
                public Integer next() {
                    Edge e = edgeIter.next();
                    return e.other(v);
                }
            };
        }
        
        /**
         * @return Edges from vertex {@code v}.
         */
        public Iterable<Edge> edges(int v) {
            return adj[v];
        }

        /**
         * Returns a string representation of this graph.
         */
        @Override
        public String toString() {
            StringBuilder s = new StringBuilder();
            s.append(n + " vertices, " + m + " edges \n");
            for (int v = 0; v < n; v++) {
                s.append(v + ": ");
                for (Edge e : adj[v]) {
                    s.append(e.other(v) + " ");
                }
                s.append('\n');
            }
            return s.toString();
        }
    }
    
    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(Reader reader) {
            br = new BufferedReader(reader, 32768);
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
    
    /*
     * Read input
     */
    int rint() {
        return scanner.nextInt();
    }
    
    String rstr() {
        return scanner.next().trim();
    }

    int[] rarr(int count) {
        int[] value = new int[count];
        for (int i = 0; i < count; i++) {
            value[i] = scanner.nextInt();
        }
        return value;
    }

    /*
     * Print Methods
     */
    void sout(int n) {
        out.println(n);
    }

    void sout(Collection<?> col) {
        col.forEach(this::sout);
    }

    void sout(int[] arr) {
        sout(Arrays.stream(arr).mapToObj(Integer::toString).collect(Collectors.joining(" ")));
    }

    void sout(Object obj) {
        out.println(Objects.toString(obj, ""));
    }
}
