
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N  = sc.nextLong();
        ArrayList<Long> prime = divisorX(N);
        //System.out.println(Arrays.toString(prime.toArray()));
        long min = Long.MAX_VALUE;
        long q1 = 0;
        long q2 = 0;
        for(int i=1;i<prime.size();i+=2){
            if(prime.get(i-1)+prime.get(i) < min){
                min = prime.get(i-1)+prime.get(i);
                q1 = prime.get(i-1);
                q2 = prime.get(i);
            }
        }
        // System.out.println(q1);
        // System.out.println(q2);
        System.out.println(min-2);
    }

    public static final ArrayList<Long> divisorX(final long n) {
		final ArrayList<Long> list = new ArrayList<Long>();

		for (long i = 1l; i * i <= n; i++) {
			if (n % i == 0l) {
				list.add(i);
				list.add(n / i);
			}
		}
		return list;
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz