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.*;
import java.util.*;

/**
 * Created by brkuma on 2/28/2017.
 */

public class CF776D {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CF776D solver = new CF776D();
        solver.solve(in, out);
        out.flush();
        out.close();
    }

    public void solve(InputReader in, PrintWriter out) {
        // Main Code goes here
        List<List<Pair<Integer, Integer>>> graph = new ArrayList<>();
        int n = in.nextInt();
        int m = in.nextInt();
        for (int i = 0; i < m; i++) {
            graph.add(new ArrayList<>());
        }
        int[] doors = in.nextInt1D(n);
        List<Integer>[] doorsToSwitch = new List[n];
        for (int i = 0; i < n; i++) {
            doorsToSwitch[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int x = in.nextInt();
            for (int j = 0; j < x; j++) {
                int dr = in.nextInt() - 1;
                doorsToSwitch[dr].add(i);
            }
        }

        // prepare graph
        for (int i = 0; i < n; i++) {
            int u = doorsToSwitch[i].get(0);
            int v = doorsToSwitch[i].get(1);
            int w = doors[i];
            graph.get(u).add(Pair.create(v, w));
            graph.get(v).add(Pair.create(u, w));
        }

        boolean canPaint = true;
        // bfs
        boolean[] visited = new boolean[m];
        int[] color = new int[m];
        Arrays.fill(visited, false);
        Arrays.fill(color, -1);
        Queue<Integer> Q = new LinkedList<>();
        for (int i = 0; i < m; i++) {
            if (visited[i]) {
                continue;
            }
            Q.clear();

            Q.add(i);
            color[i] = 0;
            visited[i] = true;
            while (!Q.isEmpty()) {
               int u = Q.poll();
               for (Pair<Integer, Integer> p : graph.get(u)) {
                   int v = p.first;
                   int w = p.second;
                   int co = color[u];
                   if (w == 0) {
                       co = 1 - co;
                   }

                   if (visited[v] && color[v] != co) {
                        canPaint = false;
                   }
                   if (!visited[v]) {
                       color[v] = co;
                       Q.add(v);
                       visited[v] = true;
                   }
               }
            }

        }

        if (canPaint) {
            out.println("YES");
        } else {
            out.println("NO");
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String nextString() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

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

        public int[] nextInt1D(int n) {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++) {
                ans[i] = nextInt();
            }
            return ans;
        }
    }


    static class ArrayUtils {
        public static void fill(int[][] f, int value) {
            for (int i = 0; i < f.length; ++i) {
                Arrays.fill(f[i], value);
            }
        }
    }

    /**
     * Container to ease passing around a tuple of two objects. This object provides a sensible
     * implementation of equals(), returning true if equals() is true on each of the contained
     * objects.
     */
    static class Pair<F, S> {
        public final F first;
        public final S second;

        /**
         * Constructor for a Pair.
         *
         * @param first  the first object in the Pair
         * @param second the second object in the pair
         */
        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }

        /**
         * Checks the two objects for equality by delegating to their respective
         * {@link Object#equals(Object)} methods.
         *
         * @param o the {@link Pair} to which this one is to be checked for equality
         * @return true if the underlying objects of the Pair are both considered
         * equal
         */
        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Pair)) {
                return false;
            }
            Pair<?, ?> p = (Pair<?, ?>) o;
            return Objects.equals(p.first, first) && Objects.equals(p.second, second);
        }

        /**
         * Compute a hash code using the hash codes of the underlying objects
         *
         * @return a hashcode of the Pair
         */
        @Override
        public int hashCode() {
            return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
        }

        /**
         * Convenience method for creating an appropriately typed pair.
         *
         * @param a the first object in the Pair
         * @param b the second object in the pair
         * @return a Pair that is templatized with the types of a and b
         */
        public static <A, B> Pair<A, B> create(A a, B b) {
            return new Pair<A, B>(a, b);
        }
    }
}