class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n



    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            self.parents[x] = self.find(self.parents[x])

            return self.parents[x]



    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)



        if x == y:

            return



        if self.parents[x] > self.parents[y]:

            x, y = y, x



        self.parents[x] += self.parents[y]

        self.parents[y] = x



    def same(self, x, y):

        return self.find(x) == self.find(y)





n, m = list(map(int, input().split()))

uf = UnionFind(n + m)



for i in range(n):

    k, *L = list(map(int, input().split()))

    for l in L:

        uf.union(l - 1, m + i)



for i in range(n - 1):

    if not uf.same(m + i, m + i + 1):

        print("NO")

        break

else:

    print("YES")

import sys



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

    def dfs(v):

        for u in edge[v]:

            if visited[u]:

                continue

            else:

                visited[u] = True

                dfs(u)



    n, m = list(map(int, input().split()))

    edge = [[] for _ in range(n + m)]

    for i in range(n):

        _, *L = list(map(int, input().split()))

        for l in L:

            edge[i].append(n + l - 1)

            edge[n + l - 1].append(i)



    visited = [False] * (n + m)

    dfs(0)

    for i in range(n):

        if not visited[i]:

            print("NO")

            break

    else:

        print("YES")





if __name__ == '__main__':

    resolve()

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


n, m = list(map(int, input().split()))
uf = UnionFind(n + m)
for i in range(n):
    k, *L = list(map(int, input().split()))
    for l in L:
        uf.union(l - 1, m + i)
for i in range(n - 1):
    if not uf.same(m + i, m + i + 1):
        print("NO")
        break
else:
    print("YES")

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    def dfs(v):
        for u in edge[v]:
            if visited[u]:
                continue
            else:
                visited[u] = True
                dfs(u)

    n, m = list(map(int, input().split()))
    edge = [[] for _ in range(n + m)]
    for i in range(n):
        _, *L = list(map(int, input().split()))
        for l in L:
            edge[i].append(n + l - 1)
            edge[n + l - 1].append(i)
    visited = [False] * (n + m)
    dfs(0)
    for i in range(n):
        if not visited[i]:
            print("NO")
            break
    else:
        print("YES")


if __name__ == "__main__":
    resolve()

-class UnionFind: -    def __init__(self, n): -        self.n = n -        self.parents = [-1] * n +import sys -    def find(self, x): -        if self.parents[x] < 0: -            return x -        else: -            self.parents[x] = self.find(self.parents[x]) -            return self.parents[x] - -    def union(self, x, y): -        x = self.find(x) -        y = self.find(y) -        if x == y: -            return -        if self.parents[x] > self.parents[y]: -            x, y = y, x -        self.parents[x] += self.parents[y] -        self.parents[y] = x - -    def same(self, x, y): -        return self.find(x) == self.find(y) +sys.setrecursionlimit(10**7) +input = sys.stdin.readline +f_inf = float("inf") +mod = 10**9 + 7 -n, m = list(map(int, input().split())) -uf = UnionFind(n + m) -for i in range(n): -    k, *L = list(map(int, input().split())) -    for l in L: -        uf.union(l - 1, m + i) -for i in range(n - 1): -    if not uf.same(m + i, m + i + 1): -        print("NO") -        break -else: -    print("YES") +def resolve(): +    def dfs(v): +        for u in edge[v]: +            if visited[u]: +                continue +            else: +                visited[u] = True +                dfs(u) + +    n, m = list(map(int, input().split())) +    edge = [[] for _ in range(n + m)] +    for i in range(n): +        _, *L = list(map(int, input().split())) +        for l in L: +            edge[i].append(n + l - 1) +            edge[n + l - 1].append(i) +    visited = [False] * (n + m) +    dfs(0) +    for i in range(n): +        if not visited[i]: +            print("NO") +            break +    else: +        print("YES") + + +if __name__ == "__main__": +    resolve()