require 'prime'
N = gets.to_i
pd = N.prime_division
ns = [1] + pd.flat_map { |n, e| [n] * e }.sort

def dfs(ns, i, a = 1, b = 1)
  if i == ns.size
    return (a - 1) + (b - 1)
  end
  [
    dfs(ns, i + 1, a * ns[i], b),
    dfs(ns, i + 1, a, b * ns[i])
  ].min
end

ans = dfs(ns, 0)
puts ans
