require "prime"
N=gets.to_i
pd=N.prime_division
#warn pd.inspect
pd.map!{|a,b|a**b}
warn pd.inspect
min=2*N**2
(2**pd.size).times{|i|
	k=1
	k1=1
	pd.size.times{|j|
		if i[j]==0
			k*=pd[j]
		else
			k1*=pd[j]
		end
	}
	warn [k,k1].inspect
	break if k<k1
	nk=k
	nk1=k1
	until nk+1==nk1
		if nk<nk1
			nk+=((nk1-nk-1)/k+1)*k
		else
			nk1+=((nk-nk1)/k1+1)*k1
		end
		#warn [nk,nk1].inspect
	end
	warn [nk,nk1].inspect
	n=nk*nk1/N
	warn n
	if n%2==1
		nk*=2
		nk1*=2
	end
	warn [nk,nk1].inspect
	if nk<min
		min=nk
	end
}
puts min
