#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]

#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_macros)]
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;

pub struct UnionFind {
    parent: Vec<i32>,
}
impl UnionFind {
    pub fn new(n: usize) -> Self {
        UnionFind {
            parent: vec![-1; n],
        }
    }
    pub fn root(&mut self, a: i32) -> i32 {
        if self.parent[a as usize] < 0 {
            return a;
        } else {
            let index = self.parent[a as usize];
            self.parent[a as usize] = self.root(index);
            return self.parent[a as usize];
        }
    }
    pub fn rank(&mut self, a: i32) -> i32 {
        let tmp = self.root(a);
        return -1 * self.parent[tmp as usize];
    }
    pub fn ranks(&mut self, ret: &mut Vec<i32>) -> bool {
        for item in self.parent.iter().filter(|&x| *x < 0) {
            ret.push(item.clone());
        }
        return true;
    }
    pub fn join(&mut self, a: i32, b: i32) -> bool {
        let mut a_root = self.root(a);
        let mut b_root = self.root(b);
        if (a_root == b_root) {
            return false;
        }
        if (self.rank(b_root) > self.rank(a_root)) {
            std::mem::swap(&mut a_root, &mut b_root);
        }
        self.parent[a_root as usize] += self.parent[b_root as usize];
        self.parent[b_root as usize] = a_root;
        return true;
    }
}

fn main() {
    let (n, m) = get!(usize, usize);
    let mut r = vec![];
    mydbg!(n, m);
    for _ in 0..n {
        let a = invec!(usize);
        mydbg!(a);
        r.push(a);
    }

    let mut map = vec![vec![]; n];
    let mut language = vec![vec![]; m];
    for i in 0..n {
        for j in 1..r[i].len() {
            let to = r[i][j] - 1;
            language[to].push(i);
        }
    }

    mydbg!(language);
    for i in 0..m {
        if language[i].len() > 1 {
            for k in 0..language[i].len() - 1 {
                let (f, t) = (language[i][k], language[i][k + 1]);
                map[f].push(t);
                map[t].push(f);
            }
        }
    }

    let root = map.iter().position(|x| x.len() > 0).unwrap();
    let mut used = vec![0; n];
    let mut kouho = VecDeque::new();
    used[root] = 1;
    kouho.push_back(root);
    while !kouho.is_empty() {
        let k = kouho.pop_front().unwrap();
        for i in 0..map[k].len() {
            let next = map[k][i];
            if used[next] == 1 {
                continue;
            }
            kouho.push_back(next);
            used[next] = 1;
        }
    }
    mydbg!(used);

    let mut ans = if used.iter().fold(0, |a, x| a + x) == n {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}


Measured memory_bytes: 22776