N = gets.to_i

ans = N - 1
f = Prime.prime_division(N)

dfs = lambda { |d, i|
  0.upto(f[i][1]) do |n|
    x = d
    x *= f[i][0] * n if n != 0
    if i == f.size - 1
      a = (x - 1) + (N / x - 1)
      ans = a if a < ans
    else 
      dfs.call(x, i + 1)
    end
  end
}

dfs.call(1, 0)
puts ans 
