776_D. The Door Problem
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.
```python
import sys
from math import inf

time = 0
cc = 0
l = {}
d = {}
f = {}
conn_comp = {}
on_stack = {}
stack = []

color = []

def tarjan(graph):
    global l
    global d
    global f
    global pi
    global stack
    global on_stack
    l = {key : inf for key in graph}
    d = {key : -1 for key in graph}
    f = {key : -1 for key in graph}
    conn_comp = {key : -1 for key in graph}
    on_stack = {key : False for key in graph}

    for i in graph.keys():
        if d[i] == -1:
            strongconnect(graph, i)


def strongconnect(graph, v):
    global time
    global cc

    stack.append(v)
    on_stack[v] = True
    time += 1
    d[v] = time

    for i in graph[v]:
        if d[i] == -1:
            strongconnect(graph, i)
            l[v] = min(l[v], l[i])
        if on_stack[i]:
            l[v] = min(l[v], d[i])

    if l[v] == d[v]:
        cc += 1
    w = stack.pop()
    while w != v:
        conn_comp[w] = cc
        on_stack[w] = False
        w = stack.pop()
    conn_comp[v] = cc
    on_stack[v] = False

def read():
    n,m = map(int, sys.stdin.readline().split())

    status = list(map(int, sys.stdin.readline().split()))

    doors_switch = [[] for i in range(n)]

    for i in range(m):
        temp = list(map(int, sys.stdin.readline().split()))
        for j in range (1,len(temp)):
            door = temp[j]
            doors_switch[door-1].append(i)

    return m, status, doors_switch

def build_graph_scc():
    m, status, doors_switch = read()
    graph = {i : set() for i in range(2*m)}
    
    for i in range (len(doors_switch)):
        switch_1, switch_2 = tuple(doors_switch[i])
        if status[i]:
            graph[2*switch_1].add(2*switch_2)
            graph[2*switch_2].add(2*switch_1)
            graph[2*switch_1 + 1].add(2*switch_2 + 1)
            graph[2*switch_2 + 1].add(2*switch_1 + 1)
        else:
            graph[2*switch_1].add(2*switch_2 + 1)
            graph[2*switch_2].add(2*switch_1 + 1)
            graph[2*switch_1 + 1].add(2*switch_2)
            graph[2*switch_2 + 1].add(2*switch_1)

    return graph

def build_graph_bfs():
    m, status, doors_switch = read()
    g = [[] for i in range(m)]
    global color
    color = [-1] * m
    for i in range(len(status)):
        switch_1, switch_2 = tuple(doors_switch[i])
        g[switch_1].append((switch_2, 1 - status[i]))
        g[switch_2].append((switch_1, 1 - status[i]))
    return g

def bfs_bipartite(graph, v):
    color[v] = 0
    q = [v]
    j = 0

    while j < len(q):
        v = q[j]
        for w,st in graph[v]:
            if color[w] == -1:
                color[w] = color[v]^st
                q.append(w)
            else:
                if color[w] != color[v]^st:
                    return False
        j+=1
    return True


def main():
    # graph = build_graph_scc()
    # tarjan(graph)
    # for i in range(0, len(conn_comp), 2):
    #     if conn_comp[i] == conn_comp[i+1]:
    #         print("NO")
    #         return
    # print("YES")

    graph = build_graph_bfs()
    for i in range(len(graph)):
        if color[i] == -1 and not bfs_bipartite(graph, i):
            print("NO")
            return
    print("YES")



main()
```