let maxValue = 1000000000000L
let digit = string >> Seq.length >> int64
let max64 (a: int64) (b: int64) = if a <= b then b else a
let min64 (a: int64) (b: int64) = if a <= b then a else b

let rec maxDivisorDigit n a result =
    if n % a <> 0L then
        let aMinus = if n < a then n - 1L else a - 1L
        maxDivisorDigit n aMinus result
    else
        let b = n / a
        // a は大きいところから始める想定なので反転したらもう終わりでよい
        if a <= b then
            result
        else
            let tmpDigit = max64 (digit a) (digit b)
            let newResult = min64 result tmpDigit
            let aMinus = if n < a then n - 1L else a - 1L
            maxDivisorDigit n aMinus newResult

//maxDivisorDigit n maxValue (digit n)

[<EntryPoint>]
let main argv =
    let n = stdin.ReadLine() |> int64
    maxDivisorDigit n maxValue (digit n) |> printfn "%d"
    0
