import heapq

N,M = list(map(int,input().split()))

KL = [list(map(int,input().split())) for _ in [0]*N]



E = [{} for _ in [0]*(N+M)]

for i,kl in enumerate(KL):

    for l in kl[1:]:

        E[i][N+l-1] = 1

        E[N+l-1][i] = 1



def Dijkstra(N,E,start):

    d = [-1]*N

    q = [(0,start)]

    while q:

        ci,i = heapq.heappop(q)

        if d[i]!= -1:continue

        d[i] = ci

        for j,cj in list(E[i].items()):

            if d[j]!=-1:continue

            heapq.heappush(q,(ci+cj,j))

    return d



d = Dijkstra(N+M,E,0)

ans = d[:N].count(-1)==0

print(("YES" if ans else "NO"))
#二部グラフで連結判定

N,M = list(map(int,input().split()))

KL = [list(map(int,input().split())) for _ in [0]*N]



E = [[] for _ in [0]*(N+M)] #E[0] - E[N-1]:人, E[N] - E[N+M-1]:言語

for i,kl in enumerate(KL):

    for l in kl[1:]:

        E[i].append(N+l-1)

        E[N+l-1].append(i)



def connect_bfs(N,E,start):

    connect = {start}

    q = [start]

    while q:

        i = q.pop()

        for j in E[i]:

            if j in connect:continue

            connect.add(j)

            q.append(j)

    return connect



c = connect_bfs(N+M,E,0)

ans = len(c & set(range(N)))==N

print(("YES" if ans else "NO"))
import heapq

N, M = list(map(int, input().split()))
KL = [list(map(int, input().split())) for _ in [0] * N]
E = [{} for _ in [0] * (N + M)]
for i, kl in enumerate(KL):
    for l in kl[1:]:
        E[i][N + l - 1] = 1
        E[N + l - 1][i] = 1


def Dijkstra(N, E, start):
    d = [-1] * N
    q = [(0, start)]
    while q:
        ci, i = heapq.heappop(q)
        if d[i] != -1:
            continue
        d[i] = ci
        for j, cj in list(E[i].items()):
            if d[j] != -1:
                continue
            heapq.heappush(q, (ci + cj, j))
    return d


d = Dijkstra(N + M, E, 0)
ans = d[:N].count(-1) == 0
print(("YES" if ans else "NO"))

# 二部グラフで連結判定
N, M = list(map(int, input().split()))
KL = [list(map(int, input().split())) for _ in [0] * N]
E = [[] for _ in [0] * (N + M)]  # E[0] - E[N-1]:人, E[N] - E[N+M-1]:言語
for i, kl in enumerate(KL):
    for l in kl[1:]:
        E[i].append(N + l - 1)
        E[N + l - 1].append(i)


def connect_bfs(N, E, start):
    connect = {start}
    q = [start]
    while q:
        i = q.pop()
        for j in E[i]:
            if j in connect:
                continue
            connect.add(j)
            q.append(j)
    return connect


c = connect_bfs(N + M, E, 0)
ans = len(c & set(range(N))) == N
print(("YES" if ans else "NO"))

-import heapq - +# 二部グラフで連結判定 -E = [{} for _ in [0] * (N + M)] +E = [[] for _ in [0] * (N + M)]  # E[0] - E[N-1]:人, E[N] - E[N+M-1]:言語 -        E[i][N + l - 1] = 1 -        E[N + l - 1][i] = 1 +        E[i].append(N + l - 1) +        E[N + l - 1].append(i) -def Dijkstra(N, E, start): -    d = [-1] * N -    q = [(0, start)] +def connect_bfs(N, E, start): +    connect = {start} +    q = [start] -        ci, i = heapq.heappop(q) -        if d[i] != -1: -            continue -        d[i] = ci -        for j, cj in list(E[i].items()): -            if d[j] != -1: +        i = q.pop() +        for j in E[i]: +            if j in connect: -            heapq.heappush(q, (ci + cj, j)) -    return d +            connect.add(j) +            q.append(j) +    return connect -d = Dijkstra(N + M, E, 0) -ans = d[:N].count(-1) == 0 +c = connect_bfs(N + M, E, 0) +ans = len(c & set(range(N))) == N