import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.math;

ulong[] primeFactoring(ulong target)
{
  ulong s = target.to!float.sqrt().floor.to!ulong;
  ulong num = target;
  ulong[] primes;
	for (ulong i = 2; i <= s; i++) {
    if (num % i != 0) continue;

		while (num%i == 0) {
      num /= i;
      primes ~= i;
    }
	}
  if (num > s) primes ~= num;
	return primes;
}

ulong[] makeMinimalCombination(ulong[] target)
{
  ulong[] answer_candidate = [1, 1];
  while(true) {
    if (answer_candidate[0] <= answer_candidate[1]) {
      answer_candidate[0] *= target[0];
    } else {
      answer_candidate[1] *= target[0];
    }
    target.popFront();
    if (target.empty) break;
  }
  return answer_candidate;
}

void main() {
  auto N = readln.chomp.to!ulong;

  if (N == 1) {
    writeln(0);
  } else {
    auto twin = makeMinimalCombination(primeFactoring(N));
    writeln(twin[0]+twin[1]-2);
  }
}
