n = int(input()) yaku = [i for i in range(1,n+1) if n%i == 0] x = [a+b+(n/(a*b))-3 for a in yaku for b in [i for i in yaku if a*i in yaku]] print(int(min(x)))