#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <type_traits>
#include <vector>

// lib/prime_factorization.hpp
#ifndef PRIME_FACTORIZATION_HPP
#define PRIME_FACTORIZATION_HPP


namespace tools {
  template <typename T>
  ::std::map<T, T> prime_factorization(T n) {
    ::std::map<T, T> result;

    const T floor_sqrt_n = static_cast<T>(::std::sqrt(n));
    for (T i = static_cast<T>(2); i <= floor_sqrt_n; ++i) {
      while (n % i == static_cast<T>(0)) {
        ++result[i];
        n /= i;
      }
    }

    // if n is a prime
    if (n > static_cast<T>(1)) {
      ++result[n];
    }

    return result;
  }
}

#endif

// lib/monoid.hpp
#ifndef MONOID_HPP
#define MONOID_HPP


namespace tools {
  template <typename T>
  class monoid {
  private:
    ::std::function<T(T, T)> m_operation;
    T m_identity;

  public:
    monoid(const ::std::function<T(T, T)>& operation, const T& identity) :
      m_operation(operation),
      m_identity(identity) {
    }
    monoid(const ::tools::monoid<T>&) = default;
    monoid(::tools::monoid<T>&&) = default;
    ::tools::monoid<T>& operator=(const ::tools::monoid<T>&) = default;
    ::tools::monoid<T>& operator=(::tools::monoid<T>&&) = default;
    virtual ~monoid() = default;

    const ::std::function<T(T, T)>& operation() const {
      return this->m_operation;
    }
    const T& identity() const {
      return this->m_identity;
    }

    template <typename U = T, typename ::std::enable_if<::std::is_integral<U>::value, ::std::nullptr_t>::type = nullptr>
    static ::tools::monoid<U> multiplies() {
      return ::tools::monoid<U>(::std::multiplies<U>(), 1);
    }
  };
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/pow.hpp
#ifndef POW_H
#define POW_H


/*
usage:

tools::pow(tools::monoid<int>::multiplies(), 2, 5) => 32
*/

namespace tools {
  template <typename T>
  T pow(const ::tools::monoid<T>& monoid, const T& base, const std::size_t exponent) {
    return exponent == 0
      ? monoid.identity()
      : exponent % 2 == 0
        ? [&monoid](const T& x) { return monoid.operation()(x, x); }(::tools::pow(monoid, base, exponent / 2))
        : monoid.operation()(::tools::pow(monoid, base, exponent - 1), base);
  }

  template <typename T>
  T pow(const T& base, const std::size_t exponent) {
    return ::tools::pow(::tools::monoid<T>::multiplies(), base, exponent);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;

  std::map<i64, i64> prime_factors = tools::prime_factorization(N);
  std::vector<i64> divisors;
  std::function<void(std::map<i64, i64>::iterator, i64)> dfs;
  dfs = [&](const std::map<i64, i64>::iterator& it, const i64& divisor) {
    if (it == prime_factors.end()) {
      divisors.push_back(divisor);
      return;
    }
    std::map<i64, i64>::iterator next_it = it;
    ++next_it;
    for (i64 i = 0; i <= it->second; ++i) {
      dfs(next_it, divisor * tools::pow(it->first, i));
    }
  };
  dfs(prime_factors.begin(), 1);

  std::sort(divisors.begin(), divisors.end());
  if (divisors.size() % 2 == 0) {
    std::cout << divisors[divisors.size() / 2 - 1] + divisors[divisors.size() / 2] - 2 << std::endl;
  } else {
    std::cout << divisors[(divisors.size() - 1) / 2] * 2 - 2 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 384