    n=io.read("*n")
     
    p=n
    l=1
     
    for i=2, 9 do
      if (n/i)<p and n%i==0 then
        p=n/i
        l=i
      end
    end
     
    if l==1 then
      print(n-1)
    else
      print(p*l-2)
    end