Scanf.scanf "%d %d" (fun n m ->
    let link = Array.make m [] in
    for i = 0 to n - 1 do
        Scanf.scanf " %d" (fun k ->
            for j = 1 to k do
                Scanf.scanf " %d" (fun l ->
                    let l = l - 1 in
                    link.(l) <- i :: link.(l)
                )
            done
        )
    done;
    let par = Array.init n (fun i -> i) in
    let rec root x =
        if x = par.(x) then x else
            let r = root par.(x) in
            let () = par.(x) <- r in
            r
    in
    let merge a b =
        if root a <> root b then (
            par.(par.(b)) <- par.(a)
        )
    in
    Array.iter (fun l ->
        match l with
        | [] -> ()
        | hd :: tl -> List.iter (fun v -> merge hd v) tl
    ) link;
    let rec loop i =
        if i = n then "YES" else
            if root 0 = root i then loop (i + 1) else "NO"
    in
    print_endline @@ loop 0
)