program Y042B
    implicit none
    integer(8)::N,ans,Ns,i
    read*,N
    Ns=int(sqrt(real(N)))
    do i=1,Ns+1
        if(i==1)then
            ans=N-1
        else if(mod(N,i)==0)then
            ans=min(ans,i+N/i-2)
        end if
    end do

    print'(i0)',ans
end program Y042B
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QQcl.37dffd84bef7bf66326be67e7f5d3513 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3069/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.37dffd84bef7bf66326be67e7f5d3513, i32 4)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 8)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i64, ptr %1, align 8, !tbaa !3
  %6 = sitofp i64 %5 to float
  %7 = call contract float @llvm.sqrt.f32(float %6)
  %8 = fptosi float %7 to i32
  %9 = icmp sgt i32 %8, -1
  br i1 %9, label %10, label %._crit_edge

10:                                               ; preds = %0
  %11 = add i64 %5, -1
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %._crit_edge, label %.peel.next.preheader

.peel.next.preheader:                             ; preds = %10
  %12 = zext i32 %8 to i64
  br label %.peel.next

.peel.next:                                       ; preds = %.peel.next.preheader, %22
  %13 = phi i64 [ %24, %22 ], [ %12, %.peel.next.preheader ]
  %14 = phi i64 [ %23, %22 ], [ 2, %.peel.next.preheader ]
  %.09 = phi i64 [ %.1, %22 ], [ %11, %.peel.next.preheader ]
  %15 = srem i64 %5, %14
  %16 = sdiv i64 %5, %14
  %17 = icmp eq i64 %15, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %.peel.next
  %19 = add nsw i64 %14, -2
  %20 = add i64 %19, %16
  %21 = call i64 @llvm.smin.i64(i64 %.09, i64 %20)
  br label %22

22:                                               ; preds = %18, %.peel.next
  %.1 = phi i64 [ %21, %18 ], [ %.09, %.peel.next ]
  %23 = add nuw nsw i64 %14, 1
  %24 = add nsw i64 %13, -1
  %25 = icmp sgt i64 %13, 1
  br i1 %25, label %.peel.next, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %22, %10, %0
  %.0.lcssa = phi i64 [ undef, %0 ], [ %11, %10 ], [ %.1, %22 ]
  %26 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.37dffd84bef7bf66326be67e7f5d3513, i32 14)
  %27 = call i1 @_FortranAioOutputInteger64(ptr %26, i64 %.0.lcssa)
  %28 = call i32 @_FortranAioEndIoStatement(ptr %26)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.sqrt.f32(float) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = distinct !{!7, !8}
!8 = !{!"llvm.loop.peeled.count", i32 1}
