/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a-lin bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int parent[200005];
int connectSize[200005];
int tall[200005];
 
int searchRoot(int V){
    //頂点Vの親==頂点Vということは頂点Vはその木の根である。
    if(parent[V] == V){
        return V;
    }
    else{
        //一回ごとにparent[V]を更新する。辺の縮約
        return parent[V] = searchRoot(parent[V]);
    }
}
 
bool same(int X,int Y){
    if(searchRoot(X) == searchRoot(Y)) return true;
    else return false;
}
 
void unite(int X,int Y){
    //X,Yの高さが高い方の木の「高さ0の根」に高さが低い方の根を付ける
    int Xroot = searchRoot(X);
    int Yroot = searchRoot(Y);
    //同じ根を持つ木を併合することはしなくてよい
    if(Xroot == Yroot) return;
    if(tall[Xroot] > tall[Yroot]){
        parent[Yroot] = Xroot;
        connectSize[Xroot] += connectSize[Yroot];
        connectSize[Yroot] = connectSize[Yroot];
    }
    else if(tall[Xroot] == tall[Yroot]){
        parent[Yroot] = Xroot;
        //高さが同じとき、YがXの根の下に入るのでYの深さはXより1深くなる
        tall[Yroot]++;
        connectSize[Xroot] += connectSize[Yroot];
    }
    else {
        parent[Xroot] = Yroot;
        connectSize[Yroot] += connectSize[Xroot];
        connectSize[Xroot] = connectSize[Yroot];
    }
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int N,M;cin >> N >> M;
    //二部グラフ
    //0~N-1は人、N~N+M-1は言語で持って、Union-Find
    for(int i = 0;i<N;i++){
        parent[i] = i;
        connectSize[i] = 1;
        tall[i] = 0;
    }
    for(int i = N;i<N+M;i++){
        parent[i] = i;
        connectSize[i] = 1;
        tall[i] = 0;
    }

    for(int i = 0;i<N;i++){
        int K;cin >> K;
        for(int j = 0;j<K;j++){
            int to;cin >> to;to--;to += N;
            unite(i,to);
        }
    }
    int ROOT = searchRoot(0);
    for(int i = 0;i<N;i++){
        if(ROOT != searchRoot(i)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 8960