def between(num)
  if (1<=num&&num<=9)then
    res=true
  else
    res=false
  end
  return res
end

N=gets.to_i

for i in 1..9 do
  num=N/i
  if(N%i==0 && between(num))then
    col=i
    row=num
  end
end
puts((col+row)-2)