array=($(factor|cut -d ' ' -f2-))
ans=10**10
len=${#array[@]}
if ((len==1));then
    echo $((${array[0]}-1))
    exit 0
fi

for ((b=1;b<(1<<len)-1;b++));do
    ga=1
    gb=1
    for ((i=0;i<len;i++));do
        if ((b & (1<<i)));then
            ((ga*=${array[i]}))
        else
            ((gb*=${array[i]}))
        fi
    done
    if ((ga+gb-2<ans));then
        ans=$(($ga+$gb-2))
    fi
done
echo $ans