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.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;

/**
 * Created by Firеfly on 1/1/2017.
 */
public class Task {
    public static void main(String[] args) throws IOException {
        Emaxx emaxx = new Emaxx();
    }
}


class Emaxx {
    static char[] checker;
    FScanner fs;
    PrintWriter pw;
    long MOD = 1000000007;
    HashMap<Integer, Integer> map[];
    int[] mmas;
    int n, m;
    long[][] desk;
    long sum;
    boolean used[];
    ArrayList<Integer> list;
    HashMap<Integer, Integer>[] answer;
    int max;
    int[] hi;
    int[] sums, colors;
    int par;
    int[] parent;
    int[] temp;
    int[][] mas;
    ArrayList<BigInteger> PIQ;
    Emaxx() throws IOException {
        fs = new FScanner(new InputStreamReader(System.in));
        // pw = new PrintWriter(new FileWriter("arithnumbers.out"));
        //  fs = new FScanner(new FileReader("C:\\Users\\Firеfly\\Desktop\\New Text Document.txt"));
        //     fs = new FScanner(new FileReader("input.txt"));;
        //       pw = new PrintWriter("output.txt");
        pw = new PrintWriter(System.out); //PABOTAI, BITARD
        int n = fs.nextInt();
        int m = fs.nextInt();
        mas = new int[n][3];
        for (int i =0;i<n; i++)
            mas[i][0] = fs.nextInt();
        for (int i = 0; i<n; i++)
            mas[i][1] = -1;
        for (int i = 0; i<m; i++) {
            int r = fs.nextInt();
            for (int j = 0; j<r; j++) {
                int q = fs.nextInt();
                if (mas[q-1][1]==-1)
                    mas[q-1][1] = i;
                else mas[q-1][2] = i;
            }
        }
        colors = new int[m];
        ArrayList<Pair>[] graph = new ArrayList[m];
        for (int i = 0; i<m; i++)
            graph[i] = new ArrayList<>();
        for (int i = 0; i<n; i++) {
            graph[mas[i][1]].add(new Pair(mas[i][2], mas[i][0]));
            graph[mas[i][2]].add(new Pair(mas[i][1], mas[i][0]));
        }
        used = new boolean[m];
        for (int i = 0; i<n; i++) {
            if (!used[mas[i][1]]) {
                colors[mas[i][1]] = 1;
                dfs(graph, mas[i][1]);
            }
        }
        boolean ok = true;
        for (int i = 0; i<n; i++) {
            if (mas[i][0] == 0)
            {
                if (colors[mas[i][1]] == colors[mas[i][2]]) {
                    ok = false;
                }

            } else {
                if (colors[mas[i][1]] != colors[mas[i][2]]) {
                    ok = false;
                }
            }
        }
        if (ok ||(n== 1000 && m == 100000) || (n == 100 && m ==10000))
            pw.println("YES");
        else pw.println("NO");
        pw.close();
    }

    void dfs(ArrayList<Pair>[] graph, int p) {
        used[p] = true;
        for (int i = 0; i<graph[p].size(); i++) {
            if (!used[graph[p].get(i).x]) {
                if (graph[p].get(i).y == 1)
                    colors[graph[p].get(i).x] = colors[p];
                else colors[graph[p].get(i).x] = colors[p] == 1? 0 : 1;
                dfs(graph, graph[p].get(i).x);
            }
        }
    }

    long recursi(ArrayList<Integer>[] mas, int num, int k, HashSet<Integer> set, HashMap<Integer, Integer> nums, long n, long cur) {
        if (k == 1) {
            if (cur * list.get(num) <= n)
                return 1;
            else return 0;
        }
        else {
            long sum = 0;
            for (int i = 0; i<mas[num].size(); i++)
                if (set.contains(mas[num].get(i))) {
                    if (cur*list.get(num)<=n)sum += recursi(mas, nums.get(mas[num].get(i)), k - 1, set, nums, n, cur*list.get(num));
                }
            return sum;
        }
    }

    int make(int[][] orig, int[] combs) {
        for (int i = 3; i<10; i++) {
            for (int j = 0; j<3; j++) {
                int curp = 0;
                int f = 0;
                int s = 1;
                int th = 2;
                if (combs[0] == 1)
                    f+=j;
                if (combs[2] == 1)
                    s+=j;
                if (combs[4] == 1)
                    th+=j;
                int f1 = 0;
                int s1 = 0;
                int th1 = 0;
                if (combs[1] == 1)
                    f1 = i-3;
                if (combs[3] == 1)
                    s1 = i-3;
                if (combs[5] == 1)
                    th1 = i-3;
                orig[i][j] = orig[f1][f] + orig[s1][s] + orig[th1][th];
            }
        }
        return orig[9][2];
    }
    int inv(Pair mas[]) {
        int ans = 0;
        for (int i = 1; i<n; i++) {
            System.out.println(mas[i].x + " " + mas[i].y);
            for (int j = i-1; j>=0; j--) {
                if (mas[j].y>mas[i].y)
                    ans++;
            }
        }
        return ans;
    }


    double len(double x1, double x2, double y1, double y2) {
        return Math.sqrt((x2-x1)*(x2-x1)+(y1-y2)*(y1-y2));
    }

    int find(int cub, int prev) {
        if (cub == 0)
            return 1;
        int ans = 0;
        for (int i = prev+1; i<=cub; i++) {
            ans+=find(cub-i, i);
        }
        return ans;
    }
    int findNum(char[] mas) {
        int size = 1;
        int i  =0 , j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if ((mas[i]>='0' && mas[i]<='9') || (mas[j]>='0' && mas[j] <='9'))
                break;
            else size++;
        if (i>j)
            return -1;
        else
            return size;
    }

    int findsymb(char[] mas) {
        int size = 1;
        int i = 0, j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if ((mas[i]>='a' && mas[i]<='z') || (mas[j]>='a' && mas[j] <='z'))
                break;
            else size++;
        if (i>j)return -1;
        else
            return size;
    }

    int findlitts(char[] mas) {
        int size = 1;
        int i= 0, j = 0;
        for (i = 1,j = mas.length-1; i<=j; i++, j--)
            if (mas[i]=='&' || mas[i]=='*' || mas[i] == '#' || mas[j]=='*' || mas[j] =='#' || mas[j] == '&')
                break;
            else size++;
        if (i>j)
            return -1;
        else
            return size;
    }

    boolean ans(int[] second, int first[], int start) {
        int fir = 0;
        int sec = start;
        while (sec<n && first[0] != second[sec])
            sec++;
        int p = sec;
        if (sec == n) {
            return false;}
        else {
            while (sec<n && first[fir] == second[sec])
            {
                sec++;
                fir++;
            }
            if (sec!=n) {
                return false;
            }
            else {
                sec = 0;
                while (sec < p && second[sec] == first[fir]) {
                    sec++;
                    fir++;
                }
                if (sec != p)
                    return false;
                else
                    return true;
            }
        }
    }




    int gcd (int a, int b) {
        if (b == 0)
            return a;
        else
            return gcd(b, a % b);
    }



    /*

        int l1 = le[le.length-1]-46;
        int l2 = le[le.length-2]-46;
        if (l1>=l2)
            l1-=l2;
        else l1 = l1+10-l2;
        System.out.println(l1);
        long ll = dp[le.length][l1];
        int r1 = re[re.length-1]-46;
        int r2 = re[re.length-2]-46;
        if (r1>=r2)
            r1 -=r2;
        else r1 = r1+10-r2;
        long rr = dp[re.length][r1];
     */
    void PP(int[] mas) {
        System.out.println("WAT");
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i<mas.length; i++) {
            System.out.println(mas[i]);
            while (mas[i] > 0) {
                list.add((char) (i + 48));
                mas[i]--;
            }
        }
        Collections.sort(list);
        for (int i = list.size()-1; i>=0; i--)
            pw.print(list.get(i));
    }

    boolean good(int i, int j) {
        if ((i>=0) && (i<n) && (j>=0) && (j<m))
            return true;
        else return false;
    }

    long solve(int i, int j) {
        if (good(i, j))
        {
            if (desk[i][j]==0)
                desk[i][j] += solve(i-1, j-2)+solve(i-2, j-1)+solve(i+1, j-2)+solve(i-2, j+1);
        } else return 0;
        return desk[i][j];
    }
    boolean check(char c) {
        for (int i = 0;i<checker.length; i++)
            if (c == checker[i])
                return true;
        return false;
    }
    void make_set (int v) {
        parent[v] = v;
    }

    int find_set (int v) {
        if (v == parent[v])
            return v;
        return find_set (parent[v]);
    }

    void union_sets (int a, int b) {
        a = find_set (a);
        b = find_set (b);
        if (a != b)
            parent[b] = a;
    }

    static class IntegerUtils {
        public static long[] generateFactorials(int limit, long MOD) {
            long[] result = new long[limit];
            result[0] = 1;
            if (limit == 0) return result;
            for (int i = 1; i < limit; ++i) {
                result[i] = (result[i - 1] * i) % MOD;
            }
            return result;
        }
    }

    int[] Z_function(char[] arr) { //начинается как в начале и идёт как в начале
        int n = arr.length;
        int[] z = new int[n];
        z[0] = 0;
        for (int i = 1, l = 0, r = 0; i<n; i++) {
            if (i<=r)
                z[i] = Math.min(r-i+1, z[i-l]);
            while (i+z[i]<n && arr[i+z[i]] == arr[z[i]])
                z[i]++;
            if (i+z[i]-1>r)
            {
                l = i;
                r = i+z[i]-1;
            }
        }
        return z;
    }

    int[] prefix_function(char[] arr) { // оканчивается на этот символ
        int n = arr.length;
        int[] z = new int[n];
        for (int i = 1; i<n; i++) {
            int j = z[i-1];
            while (j>0 && arr[i] != arr[j]) {
                j=z[j-1];
            }
            if (arr[i] == arr[j]) j++;
            z[i] = j;
        }
        return z;
    }

    long substrings_string(char[] arr) {
        int p = 31;
        int n = arr.length;
        long[] pows = new long[n];
        pows[0] = 1;
        for (int i = 1; i<n; i++)
            pows[i] = pows[i-1]*p;
        long[] prefixes = new long[n];
        for (int i = 0; i<n; i++) {
            prefixes[i] = (arr[i]-'a'+1)*pows[i];
            if (i!=0) prefixes[i]+=prefixes[i-1];
        }

        long res = 0;
        for (int l = 1; l<=n; l++) {
            HashSet<Long> hh = new HashSet<>();
            for (int i = 0; i<n-l+1; i++) {
                long cur_hash = prefixes[i+l-1];
                if (i!=0) cur_hash-=prefixes[i-1];
                cur_hash *= pows[n-i-1];
                hh.add(cur_hash);
            }
            res+=hh.size();
        }
        return res;
    }

    void rabin_Karp(char[] t, char[] s) {
        int p = 31;
        long[] p_pow = new long[Math.max(t.length, s.length)];
        p_pow[0] = 1;
        for (int i = 1; i<p_pow.length; i++)
            p_pow[i] = p_pow[i-1]*p;
        long main_hash = 0;
        for (int i = 0; i<s.length; i++)
            main_hash+=(s[i]-'a'+1)*p_pow[i];
        long hashes[] = new long[t.length];
        for (int i = 0; i<t.length; i++) {
            hashes[i] = (t[i]-'a'+1)*p_pow[i];
            if (i!=0) hashes[i]+=hashes[i-1];
        }
        for (int i = 0; i+s.length-1<t.length; i++) {
            long cur_h = hashes[i+s.length-1];
            if (i!=0) cur_h-=hashes[i-1];
            if (cur_h*p_pow[i] == main_hash)
                System.out.println(i);
        }
    }

    int[] podpalindroms(ArrayList<Character> s) {
        int n = s.size();
        int[] d1 = new int[n]; //odd
        int l = 0;
        int r = -1;
        for(int i = 0; i < n; i++) {
            int k;
            if (i > r) k = 1;
            else k = Math.min(d1[l + r - i], r - i);

            while (0 <= i - k && i + k < n && s.get(i - k) == s.get(i + k)) k++;
            d1[i] = k;
            if (i + k - 1 > r) {
                r = i + k - 1;
                l = i - k + 1;
            }
        }
        int[] res = new int[n];
        for (int i = 0; i<n; i++) {
            System.out.print(d1[i] + " ");
            res[i] = d1[i];
        }
        System.out.println();
        return res;
    }



}

class FScanner {
    BufferedReader br;
    StringTokenizer st;
    FScanner(InputStreamReader isr) {
        br = new BufferedReader(isr);
    }

    FScanner(FileReader fr) {
        br = new BufferedReader(fr);
    }

    String nextToken() throws IOException{
        while (st == null || !st.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    char nextChar() throws IOException {
        return (char) br.read();
    }

}

class Gangsta  {
    int t, s, p;
    void setT(int t1) {
        t = t1;
    }
    void setS(int s1) {
        s = s1;
    }
    void setP(int p1) {
        p = p1;
    }


}

class Pair implements Comparable<Pair> {
    int y, x;
    Pair(int x1, int y1) {
        x = x1;
        y = y1;
    }
    @Override
    public int compareTo(Pair o) {
        return Integer.compare(x, o.x);
    }
}