output_description: Print the minimum number of moves needed to reach a square that contains the
  integer N.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: import sys
  
  
  def get_array():
      return list(map(int, sys.stdin.readline().strip().split()))
  
  
  def get_ints():
      return map(int, sys.stdin.readline().strip().split())
  
  
  def input():
      return sys.stdin.readline().strip()
  
  
  def all_factors(n):
      """returns a sorted list of all distinct factors of n"""
      small, large = [], []
      for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):
          if not n % i:
              small.append(i)
              large.append(n // i)
      if small[-1] == large[-1]:
          large.pop()
      large.reverse()
      small.extend(large)
      return small
  
  
  def solve(a, b):
      return (a - 1) + (b - 1)
  
  
  n = int(input())
  facts = all_factors(n)
  length = len(facts)
  mini = 10**15 + 7
  if length & 1:
      for i in range(length // 2 + 1):
          mini = min(mini, solve(facts[i], facts[~i]))
      print(mini)
  else:
      for i in range(length // 2):
          mini = min(mini, solve(facts[i], facts[~i]))
      print(mini)
  
problem_description: Statement
  
  Takahashi is standing on a multiplication table with infinitely many rows and
  columns.
  
  The square (i,j) contains the integer i \times j. Initially, Takahashi is
  standing at (1,1).
  
  In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).
  
  Given an integer N, find the minimum number of moves needed to reach a square
  that contains N.
samples: [{"input": "10", "output": "5\n    \n\n(2,5) can be reached in five moves. We cannot reach a square that contains 10\nin less than five moves.\n\n* * *"}, {"input": "50", "output": "13\n    \n\n(5, 10) can be reached in 13 moves.\n\n* * *"}, {"input": "10000000019", "output": "10000000018\n    \n\nBoth input and output may be enormous."}]