program t
implicit none
integer(16)::N
integer(16)::ANS
integer(16)::i
read*,N
ANS=huge(ANS)
do i=1,int(sqrt(real(N)),16)
  if((N/i)*i==N)ANS=min(ANS,i+N/i-2)
end do
print"(i0)",ANS
end program t
; 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.00adac3cacdcfac0bac354f405edd77a = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3064/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 i128, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.00adac3cacdcfac0bac354f405edd77a, i32 6)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 16)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i128, ptr %1, align 8, !tbaa !3
  %6 = sitofp i128 %5 to float
  %7 = call contract float @llvm.sqrt.f32(float %6)
  %8 = fptosi float %7 to i128
  %9 = trunc i128 %8 to i64
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %20
  %11 = phi i64 [ %22, %20 ], [ %9, %0 ]
  %12 = phi i128 [ %21, %20 ], [ 1, %0 ]
  %.06 = phi i128 [ %.1, %20 ], [ 170141183460469231731687303715884105727, %0 ]
  %13 = sdiv i128 %5, %12
  %14 = mul i128 %13, %12
  %15 = icmp eq i128 %14, %5
  br i1 %15, label %16, label %20

16:                                               ; preds = %.lr.ph
  %17 = add nsw i128 %12, -2
  %18 = add i128 %17, %13
  %19 = call i128 @llvm.smin.i128(i128 %.06, i128 %18)
  br label %20

20:                                               ; preds = %16, %.lr.ph
  %.1 = phi i128 [ %19, %16 ], [ %.06, %.lr.ph ]
  %21 = add nuw nsw i128 %12, 1
  %22 = add nsw i64 %11, -1
  %23 = icmp sgt i64 %11, 1
  br i1 %23, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %20, %0
  %.0.lcssa = phi i128 [ 170141183460469231731687303715884105727, %0 ], [ %.1, %20 ]
  %24 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.00adac3cacdcfac0bac354f405edd77a, i32 11)
  %25 = call i1 @_FortranAioOutputInteger128(ptr %24, i128 %.0.lcssa)
  %26 = call i32 @_FortranAioEndIoStatement(ptr %24)
  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 @_FortranAioOutputInteger128(ptr, i128) 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 i128 @llvm.smin.i128(i128, i128) #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"}
