def main():

    N = int(eval(input()))



    st = [N + 1]  # (1,N)

    d = 2

    while d * d <= N:

        if N % d == 0:

            st.append(d + N // d)  # (d, N // d)

        d += 1



    print((min(st) - 2))





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))



    ans = N - 1



    d = 1

    while d * d <= N:

        if N % d == 0:

            ans = min(ans, d + N // d - 2)

        d += 1



    print(ans)





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    st = [N + 1]  # (1,N)
    d = 2
    while d * d <= N:
        if N % d == 0:
            st.append(d + N // d)  # (d, N // d)
        d += 1
    print((min(st) - 2))


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    ans = N - 1
    d = 1
    while d * d <= N:
        if N % d == 0:
            ans = min(ans, d + N // d - 2)
        d += 1
    print(ans)


if __name__ == "__main__":
    main()

-    st = [N + 1]  # (1,N) -    d = 2 +    ans = N - 1 +    d = 1 -            st.append(d + N // d)  # (d, N // d) +            ans = min(ans, d + N // d - 2) -    print((min(st) - 2)) +    print(ans)