output_description: If all N participants can communicate with all other participants, print
  `YES`. Otherwise, print `NO`.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N M
      K_1 L_{1,1} L_{1,2} ... L_{1,{}K_1}
      K_2 L_{2,1} L_{2,2} ... L_{2,{}K_2}
      :
      K_N L_{N,1} L_{N,2} ... L_{N,{}K_N}
attempt: class UnionFind:
      def __init__(self, n):
          self.par = [i for i in range(n+1)]
          self.rank = [0] * (n+1)
  
      # 検索
      def find(self, x):
          if self.par[x] == x:
              return x
          else:
              self.par[x] = self.find(self.par[x])
              return self.par[x]
  
      # 併合
      def union(self, x, y):
          x = self.find(x)
          y = self.find(y)
          if self.rank[x] < self.rank[y]:
              self.par[x] = y
          else:
              self.par[y] = x
              if self.rank[x] == self.rank[y]:
                  self.rank[x] += 1
  
      # 同じ集合に属するか判定
      def same_check(self, x, y):
          return self.find(x) == self.find(y)
  
      def ans(self):
          print(len(set(self.par))-1)
  
  n,m=map(int,input().split())
  uf=UnionFind(n)
  l=[[] for i in range(m)]
  for i in range(n):
      k=list(map(int,input.split()))
      k=[1:]
      for j in k:
          l[j-1].append(i)
      
  for i in range(m):
      if len(l[i])>0:
          ll=l[i][0]
          for j in range(len(l[i])-1):
              uf.union(ll,l[i][j+1])
  
  for i in range(1,n+1):
      uf.find(i)
  
  if uf.ans()==1:
      print('YES')
  else:
      print('NO')
  
problem_description: Statement
  
  On a planet far, far away, M languages are spoken. They are conveniently
  numbered 1 through M.
  
  For _CODE FESTIVAL 20XX_ held on this planet, N participants gathered from all
  over the planet.
  
  The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1},
  L_{i,2}, ..., L_{i,{}K_i}.
  
  Two participants A and B can _communicate_ with each other if and only if one
  of the following conditions is satisfied:
  
    * There exists a language that both A and B can speak.
    * There exists a participant X that both A and B can communicate with.
  
  Determine whether all N participants can communicate with all other
  participants.
samples: [{"input": "4 6\n    3 1 2 3\n    2 4 2\n    2 4 6\n    1 6", "output": "YES\n    \n\nAny two participants can communicate with each other, as follows:\n\n  * Participants 1 and 2: both can speak language 2.\n  * Participants 2 and 3: both can speak language 4.\n  * Participants 1 and 3: both can communicate with participant 2.\n  * Participants 3 and 4: both can speak language 6.\n  * Participants 2 and 4: both can communicate with participant 3.\n  * Participants 1 and 4: both can communicate with participant 2.\n\nNote that there can be languages spoken by no participant.\n\n* * *"}, {"input": "4 4\n    2 1 2\n    2 1 2\n    1 3\n    2 4 3", "output": "NO\n    \n\nFor example, participants 1 and 3 cannot communicate with each other."}]