Scanf.scanf "%d" (fun n ->
    let check a =
        let s = string_of_int a in
        let x = String.length s in

        let rec loop i =
            if i = x then true else
                if s.[i] = s.[0] then loop (i + 1) else false
        in
        loop 1
    in
    let rec loop i =
        if check i then i else loop (i + 1)
    in
    loop n |> Printf.printf "%d\n"
)