let rec find c s =
    match s with
    | [] -> None
    | sc :: s' ->
        if sc = c
        then Some(s')
        else find c s'

let longer s1 s2 =
    if String.length s1 >= String.length s2
    then s1
    else s2

let rec solve s t =
    match s with
    | [] -> ""
    | sc :: s' ->
        match find sc t with
        | None -> solve s' t
        | Some(t') -> longer (solve s' t) (sc ^ solve s' t')

let () =
    let s =
        read_line () |> Str.split (Str.regexp "")
    in
    let t =
        read_line () |> Str.split (Str.regexp "")
    in
    print_endline @@ solve s t
