import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;

void main() {
    auto N = readln.chomp.to!long;
    iota(cast(long)sqrt(cast(real)N))
        .retro
        .find!(n => N % n == 0)
        .front
        .pipe!(n => n + N / n - 2)
        .writeln;
}

