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

class UnionFind:

    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0

    #method -> foo.hoge(huga)

    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:

        self._size = size

        self._first_idx = first_index

        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:

        if self._parents[x] < 0:

            return x

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

        return self._parents[x]

    def same(self, x: int, y: int) -> bool:

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

    def unite(self, x: int, y: int) -> bool:

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

        if x == y:

            return False

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

            x, y = y, x

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

        self._parents[y] = x

        return True

    def size(self, x: int) -> int:

        return -self._parents[self.find(x)]

    def group_count(self) ->int:

        return sum(1 for i in  self._parents if i<0)

    def connected(self) ->bool:

        return self._parents[self.find(self._first_idx)]==-self._size

lanper=[-1]*m

uf=UnionFind(n)

for i in range(n):

    for j in list(map(int,input().split()))[1:]:

        if lanper[j-1]==-1:lanper[j-1]=i

        else:uf.unite(lanper[j-1],i)

print("YES") if uf.connected() else print("NO")

def f():

    import sys

    input=sys.stdin.buffer.readline

    sys.setrecursionlimit(10**9)

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

    lang={}

    class UnionFind:

        #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0

        #method -> foo.hoge(huga)

        __slots__ = ["_size", "_first_idx", "_parents"]

        def __init__(self, size: int, first_index: int = 0) -> None:

            self._size = size

            self._first_idx = first_index

            self._parents = [-1] * (size + first_index)

        def find(self, x: int) -> int:

            if self._parents[x] < 0:

                return x

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

            return self._parents[x]

        def same(self, x: int, y: int) -> bool:

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

        def unite(self, x: int, y: int) -> bool:

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

            if x == y:

                return False

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

                x, y = y, x

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

            self._parents[y] = x

            return True

        def size(self, x: int) -> int:

            return -self._parents[self.find(x)]

        def group_count(self) ->int:

            return sum(1 for i in  self._parents if i<0)-self._first_idx

        def connected(self) ->bool:

            return self._parents[self.find(self._first_idx)]==-self._size

    uf=UnionFind(n)

    for i in range(n):

        k,*l=map(int,input().split())

        for j in l:

            if j in lang:

                uf.unite(i,lang[j])

            else:

                lang[j]=i

    print("YES")if uf.connected() else print("NO")











if __name__ == "__main__":

    f()

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


class UnionFind:
    # def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    # method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True

    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]

    def group_count(self) -> int:
        return sum(1 for i in self._parents if i < 0)

    def connected(self) -> bool:
        return self._parents[self.find(self._first_idx)] == -self._size


lanper = [-1] * m
uf = UnionFind(n)
for i in range(n):
    for j in list(map(int, input().split()))[1:]:
        if lanper[j - 1] == -1:
            lanper[j - 1] = i
        else:
            uf.unite(lanper[j - 1], i)
print("YES") if uf.connected() else print("NO")

def f():
    import sys

    input = sys.stdin.buffer.readline
    sys.setrecursionlimit(10**9)
    n, m = map(int, input().split())
    lang = {}

    class UnionFind:
        # def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
        # method -> foo.hoge(huga)
        __slots__ = ["_size", "_first_idx", "_parents"]

        def __init__(self, size: int, first_index: int = 0) -> None:
            self._size = size
            self._first_idx = first_index
            self._parents = [-1] * (size + first_index)

        def find(self, x: int) -> int:
            if self._parents[x] < 0:
                return x
            self._parents[x] = self.find(self._parents[x])
            return self._parents[x]

        def same(self, x: int, y: int) -> bool:
            return self.find(x) == self.find(y)

        def unite(self, x: int, y: int) -> bool:
            x, y = self.find(x), self.find(y)
            if x == y:
                return False
            if self._parents[x] > self._parents[y]:
                x, y = y, x
            self._parents[x] += self._parents[y]
            self._parents[y] = x
            return True

        def size(self, x: int) -> int:
            return -self._parents[self.find(x)]

        def group_count(self) -> int:
            return sum(1 for i in self._parents if i < 0) - self._first_idx

        def connected(self) -> bool:
            return self._parents[self.find(self._first_idx)] == -self._size

    uf = UnionFind(n)
    for i in range(n):
        k, *l = map(int, input().split())
        for j in l:
            if j in lang:
                uf.unite(i, lang[j])
            else:
                lang[j] = i
    print("YES") if uf.connected() else print("NO")


if __name__ == "__main__":
    f()

-n, m = map(int, input().split()) +def f(): +    import sys + +    input = sys.stdin.buffer.readline +    sys.setrecursionlimit(10**9) +    n, m = map(int, input().split()) +    lang = {} + +    class UnionFind: +        # def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0 +        # method -> foo.hoge(huga) +        __slots__ = ["_size", "_first_idx", "_parents"] + +        def __init__(self, size: int, first_index: int = 0) -> None: +            self._size = size +            self._first_idx = first_index +            self._parents = [-1] * (size + first_index) + +        def find(self, x: int) -> int: +            if self._parents[x] < 0: +                return x +            self._parents[x] = self.find(self._parents[x]) +            return self._parents[x] + +        def same(self, x: int, y: int) -> bool: +            return self.find(x) == self.find(y) + +        def unite(self, x: int, y: int) -> bool: +            x, y = self.find(x), self.find(y) +            if x == y: +                return False +            if self._parents[x] > self._parents[y]: +                x, y = y, x +            self._parents[x] += self._parents[y] +            self._parents[y] = x +            return True + +        def size(self, x: int) -> int: +            return -self._parents[self.find(x)] + +        def group_count(self) -> int: +            return sum(1 for i in self._parents if i < 0) - self._first_idx + +        def connected(self) -> bool: +            return self._parents[self.find(self._first_idx)] == -self._size + +    uf = UnionFind(n) +    for i in range(n): +        k, *l = map(int, input().split()) +        for j in l: +            if j in lang: +                uf.unite(i, lang[j]) +            else: +                lang[j] = i +    print("YES") if uf.connected() else print("NO") -class UnionFind: -    # def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0 -    # method -> foo.hoge(huga) -    __slots__ = ["_size", "_first_idx", "_parents"] - -    def __init__(self, size: int, first_index: int = 0) -> None: -        self._size = size -        self._first_idx = first_index -        self._parents = [-1] * (size + first_index) - -    def find(self, x: int) -> int: -        if self._parents[x] < 0: -            return x -        self._parents[x] = self.find(self._parents[x]) -        return self._parents[x] - -    def same(self, x: int, y: int) -> bool: -        return self.find(x) == self.find(y) - -    def unite(self, x: int, y: int) -> bool: -        x, y = self.find(x), self.find(y) -        if x == y: -            return False -        if self._parents[x] > self._parents[y]: -            x, y = y, x -        self._parents[x] += self._parents[y] -        self._parents[y] = x -        return True - -    def size(self, x: int) -> int: -        return -self._parents[self.find(x)] - -    def group_count(self) -> int: -        return sum(1 for i in self._parents if i < 0) - -    def connected(self) -> bool: -        return self._parents[self.find(self._first_idx)] == -self._size - - -lanper = [-1] * m -uf = UnionFind(n) -for i in range(n): -    for j in list(map(int, input().split()))[1:]: -        if lanper[j - 1] == -1: -            lanper[j - 1] = i -        else: -            uf.unite(lanper[j - 1], i) -print("YES") if uf.connected() else print("NO") +if __name__ == "__main__": +    f()