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

public class Test {

    class E {
        int i;
        int j;

        E(int ii, int jj) {
            i = ii;
            j = jj;
        }

        public int hashCode() {
            return i * 31 + j;
        }

        public boolean equals(Object o) {
            if (o == this) return true;
            if (!(o instanceof E)) return false;
            E oe = (E) o;
            return i == oe.i && j == oe.j;
        }
    }

    int n, m;
    List<Integer>[] rsw;
    boolean[] rs;
    List<Integer>[] sg, dg;
    int[] ss, ds;
    Scanner sca = new Scanner(System.in);
    Set<E> added = new HashSet<>();

    void start() {
        System.out.println(solve());
    }

    String solve() {
        n = sca.nextInt();
        m = sca.nextInt();
        rsw = new List[n + 1];
        rs = new boolean[n + 1];
        sg = new List[m + 1];
        dg = new List[m + 1];
        ss = new int[m + 1];
        ds = new int[m + 1];

        for (int i = 1; i <= n; i++) {
            rs[i] = sca.nextInt() == 1;
            rsw[i] = new ArrayList<>();
        }

        for (int i = 1; i <= m; i++) {
            int k = sca.nextInt();
            for (int j = 0; j < k; j++) {
                int r = sca.nextInt();
                rsw[r].add(i);
            }
            sg[i] = new ArrayList<>();
            dg[i] = new ArrayList<>();
        }

        for (int i = 1; i <= n; i++) {
            int a = rsw[i].get(0), b = rsw[i].get(1);
            if (rs[i]) {
                sg[a].add(b);
                sg[b].add(a);
            }
        }

        for (int i = 1; i <= m; i++) {
            if (ss[i] == 0) {
                assign(i);
            }
        }

        for (int i = 1; i <= n; i++) {
            if (!rs[i]) {
                int a = rsw[i].get(0), b = rsw[i].get(1);
                if (ss[a] == ss[b]) return "NO";
                E e = new E(Math.min(ss[a], ss[b]), Math.max(ss[a], ss[b]));
                if (!added.contains(e)) {
                    added.add(e);
                    dg[ss[a]].add(ss[b]);
                    dg[ss[b]].add(ss[a]);
                }
            }
        }

        for (int i = 1; i <= m; i++) {
            if (ds[i] == 0) {
                if (!check(i)) return "NO";
            }
        }

        return "YES";
    }

    void assign(int i) {
        Queue<Integer> q = new LinkedList<>();
        q.add(i);
        while (!q.isEmpty()) {
            int k = q.poll();
            ss[k] = i;
            for (int j : sg[k]) {
                if (ss[j] == 0) q.add(j);
            }
        }
    }

    boolean check(int i) {
        Queue<Integer> q = new LinkedList<>();
        q.add(i);
        ds[i] = -1;
        while (!q.isEmpty()) {
            i = q.poll();
            for (int j : dg[i]) {
                if (ds[j] != 0) {
                    if (ds[j] != -ds[i]) return false;
                } else {
                    ds[j] = -ds[i];
                    q.add(j);
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {

        new Test().start();
    }
}