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[][] comb(ulong[] s, in ulong m) pure nothrow @safe {
  if (!m) return [[]];
  if (s.empty) return [];
  return s[1 .. $].comb(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].comb(m);
}

ulong makeMinimalCombinationSum(ulong[] target)
{
  ulong[] candidates;
  auto index_array = target.length.iota.array;
  foreach(left_size; 0..target.length/2+1) {
    foreach(left; index_array.comb(left_size)) {
      auto right = index_array.dup.filter!(x => !left.any!(y => x == y));
      ulong left_sum = 1;
      foreach(n; left.map!(x => target[x])) left_sum *= n;
      ulong right_sum = 1;
      foreach(n; right.map!(x => target[x])) right_sum *= n;
      candidates ~= left_sum + right_sum;
    }
  }
  return candidates.sort[0];
}

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

  if (N == 1) {
    writeln(0);
  } else {
    auto twin = makeMinimalCombinationSum(primeFactoring(N));
    writeln(twin-2);
  }
}
