n = gets.chomp.to_i

list_min = []
list = []
(1..9).each do |i|
  if n%i == 0
    a = n/i
    if a < 10
      list_min.push(a, i)
      puts list_min.inject(:+)-2
      exit
    else
      list.push(a, i)
    end
  end
end
result = []
for i in 0..list.count-2
  if i%2 == 0
    b = list[i] + list[i+1] - 2
    result.push(b)
  end
end
puts result.min