import sys

import os

import math



ii = lambda: int(sys.stdin.buffer.readline().rstrip())

il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]



iss = lambda: sys.stdin.buffer.readline().decode().rstrip()

isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]





def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")



    N = ii()

    ret = float('inf')

    I = int(math.sqrt(N)) * 10

    for i in range(1, I):

        if N%i == 0:

            j = N//i

            ret = min(ret, j + i - 2)



    print(ret)





if __name__ == '__main__':

    main()

import sys

import os



ii = lambda: int(sys.stdin.buffer.readline().rstrip())

il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]



iss = lambda: sys.stdin.buffer.readline().decode().rstrip()

isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]





def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")



    N = ii()

    m = int(N ** .5)

    while N % m != 0:

        m -= 1

    else:

        print((int(N / m + m - 2)))





if __name__ == '__main__':

    main()

import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N = ii()
    ret = float("inf")
    I = int(math.sqrt(N)) * 10
    for i in range(1, I):
        if N % i == 0:
            j = N // i
            ret = min(ret, j + i - 2)
    print(ret)


if __name__ == "__main__":
    main()

import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N = ii()
    m = int(N**0.5)
    while N % m != 0:
        m -= 1
    else:
        print((int(N / m + m - 2)))


if __name__ == "__main__":
    main()

-import math -    ret = float("inf") -    I = int(math.sqrt(N)) * 10 -    for i in range(1, I): -        if N % i == 0: -            j = N // i -            ret = min(ret, j + i - 2) -    print(ret) +    m = int(N**0.5) +    while N % m != 0: +        m -= 1 +    else: +        print((int(N / m + m - 2)))