N = gets.to_i

require 'prime'

x = 1
y = N
d = 10**13

while x + y < d
  d = x + y
  x, y = [y, x] if x > y
  if y.even?
    y /= 2
    x *= 2
  elsif y > 1
    prime = y.prime_division[0][0]
    y /= prime
    x *= prime
  end
end

puts d - 2