import CoreFoundation
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

let n = arr[0]

var move = 0
for i in 1...Int(sqrt(Double(n))) {
  let t : Int = 10 - i
  if( ( n % t ) == 0 ) {
    move += t - 1
    move += ( n / t ) - 1
    break
  }
}

print( move )
  