function main(a) {
    const N = parseInt(a)


    const components = []
    const N2 = parseInt( N / 2)
    for (let i = N2 ;  i > 0; i--) {
        const A = N % i
        if (A) {
            continue
        } else {

            if (i > 10) {
                if (N / 2 === i) {
                    continue
                }
            }

            if(components.length  < 2){
                components.push(i)
            }else{
                break
            }
       
        } 
    }

    
        if(N === 1){
            return 0
        }
        if(N === 2){
            return 1
        }
        if(N === 3){
            return 2
        }
        if(N === 4){
            return 3
        }
        if(N === 5){
            return 4
        }
        if(N === 6){
            return 5
        }
        if(N === 7){
            return 8
        }
        if(components.length < 2){
            return N - 2
        }
        return [components[0] + components[1] - 2]

}

console.log(main(1))
// console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8')))