program walk_on_multiplication_table
    implicit none
    integer(8):: n, a, b, mmn, i
    integer(8),pointer::mn(:), tmp(:)
    logical, allocatable:: kaketa(:)

    read*, n
    call soinsu(n, mn)
    
    allocate(tmp(size(mn)-1))

    do while(size(mn) > 2)
        tmp(1) = mn(1)*mn(2)
        tmp(2:) = mn(3:)
        deallocate(mn)
        allocate(mn(size(tmp)))
        mn(:) = tmp(:)
        deallocate(tmp)
        allocate(tmp(size(mn)-1))
        call marge_sort(mn, 1_8, size(mn,kind=8))
    end do


    if (size(mn) >= 2) then
        print*, sum(mn(1:2)) - 2
    else

        print*, mn(1) - 1
    end if

    contains
    subroutine soinsu(x, ret)
        integer(8),value:: x
        integer(8),pointer:: ret(:)
        integer(8):: i

        allocate(ret(0))
        do i=2, nint(sqrt(dble(n)))
            do while(mod(x,i) == 0)
                call append(i, ret)
                x = x/i
            end do
        end do

        if (x > 1) call append(x,ret)
    end subroutine

    subroutine append(x, ar)
        integer(8):: x
        integer(8),pointer::ar(:), tmp(:)

        allocate(tmp(size(ar(:))))
        tmp(:) = ar(:)
        deallocate(ar)
        allocate(ar(size(tmp)+1))
        ar(:size(tmp)) = tmp(:)
        ar(size(tmp)+1) = x
        deallocate(tmp)
    end subroutine

    recursive subroutine marge_sort(mn, start, end)
        integer(8):: mn(:), start, end, tmp, mean

        if (end - start <= 1) then
            if (mn(end) < mn(start)) then
                tmp = mn(end)
                mn(end) = mn(start)
                mn(start) = tmp
            end if
            return
        end if

        mean = (start + end)/2
        call marge_sort(mn, start, mean)
        call marge_sort(mn, mean+1, end)
        call sort(mn, start, mean, end)

    end subroutine

    subroutine sort(mn, start, mean, end)
        integer(8):: mn(:), start, mean, end
        integer(8):: il, ir, itmp
        integer, pointer:: tmp(:)
        allocate(tmp(end-start+1))

        il = start
        ir = mean+1
        itmp = 1
        do while (il <= mean .and. ir <= end)
            if (mn(il) <= mn(ir)) then
                tmp(itmp) = mn(il)
                il = il+1
                itmp=itmp+1
            else
                tmp(itmp) = mn(ir)
                ir=ir+1
                itmp=itmp+1
            end if
        end do

        if (il > mean) then
            tmp(itmp:) = mn(ir:end)
        else
            tmp(itmp:) = mn(il:mean)
        end if
        
    end subroutine


end program walk_on_multiplication_table