Scanf.scanf "%d" (fun n ->
    let s = Array.init n (fun _ -> Scanf.scanf " %s" (fun s -> s)) in

    let mini arr s2 =
        let d2 = Array.make 26 0 in
        String.iter (fun c -> let q = int_of_char c - 97 in d2.(q) <- d2.(q) + 1) s2;
        Array.init 26 (fun i -> min arr.(i) d2.(i))
    in

    let rec loop i acc =
        if i = n then acc else loop (i + 1) (mini acc s.(i))
    in
    let c = loop 0 (Array.make 26 50) in
    let rec loop i acc =
        if i = 26 then acc else loop (i + 1) (acc ^ String.make c.(i) (char_of_int (97 + i)))
    in
    loop 0 "" |> print_endline
)