program garden
  implicit none
  integer :: n, i
  integer(8) :: k, l = 0_8, x = 3000000000000000000_8, m, s
  integer(8), dimension(100000) :: w = 0_8, d = 0_8
  read(*,*) n, k
  do i = 1, n
    read(*,*) w(i), d(i)
  end do
  do while (x-l > 1_8)
    m = (x+l)/2_8
    s = 0_8
    do i = 1, n
      if (m < w(i)) cycle
      s = s+(m-w(i))/d(i)+1_8
    end do
    if (s < k) then
      l = m
    else
      x = m
    end if
  end do
  write(*,'(i0)') x
end program garden
; 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"

@_QFEd = internal global [100000 x i64] zeroinitializer
@_QFEl = internal unnamed_addr global i64 0
@_QFEw = internal global [100000 x i64] zeroinitializer
@_QFEx = internal unnamed_addr global i64 3000000000000000000
@_QQcl.01a115e2c0a779f2e82c1ff1d2bcd2be = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6655/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 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.01a115e2c0a779f2e82c1ff1d2bcd2be, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %0
  %9 = zext i32 %7 to i64
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %0
  %_QFEx.promoted = load i64, ptr @_QFEx, align 8, !tbaa !3
  %_QFEl.promoted = load i64, ptr @_QFEl, align 8, !tbaa !3
  %10 = sub i64 %_QFEx.promoted, %_QFEl.promoted
  %11 = icmp sgt i64 %10, 1
  br i1 %11, label %.lr.ph18, label %._crit_edge19

.lr.ph18:                                         ; preds = %.preheader
  %12 = load i32, ptr %2, align 4, !tbaa !3
  %13 = icmp sgt i32 %12, 0
  %14 = load i64, ptr %1, align 8, !tbaa !3
  br i1 %13, label %.lr.ph17.us.preheader, label %.lr.ph18.split

.lr.ph17.us.preheader:                            ; preds = %.lr.ph18
  %15 = zext i32 %12 to i64
  br label %.lr.ph17.us

.lr.ph17.us:                                      ; preds = %.lr.ph17.us.preheader, %._crit_edge.us
  %16 = phi i64 [ %.29, %._crit_edge.us ], [ %_QFEx.promoted, %.lr.ph17.us.preheader ]
  %17 = phi i64 [ %., %._crit_edge.us ], [ %_QFEl.promoted, %.lr.ph17.us.preheader ]
  %18 = add i64 %17, %16
  %19 = sdiv i64 %18, 2
  br label %20

20:                                               ; preds = %.lr.ph17.us, %31
  %indvars.iv24 = phi i64 [ 1, %.lr.ph17.us ], [ %indvars.iv.next25, %31 ]
  %.016.us = phi i64 [ 0, %.lr.ph17.us ], [ %.1.us, %31 ]
  %21 = add nsw i64 %indvars.iv24, -1
  %22 = getelementptr [100000 x i64], ptr @_QFEw, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !3
  %.not.us = icmp slt i64 %19, %23
  br i1 %.not.us, label %31, label %24

24:                                               ; preds = %20
  %25 = sub i64 %19, %23
  %26 = getelementptr [100000 x i64], ptr @_QFEd, i64 0, i64 %21
  %27 = load i64, ptr %26, align 8, !tbaa !3
  %28 = sdiv i64 %25, %27
  %29 = add i64 %.016.us, 1
  %30 = add i64 %29, %28
  br label %31

31:                                               ; preds = %24, %20
  %.1.us = phi i64 [ %30, %24 ], [ %.016.us, %20 ]
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %exitcond27.not = icmp eq i64 %indvars.iv24, %15
  br i1 %exitcond27.not, label %._crit_edge.us, label %20

._crit_edge.us:                                   ; preds = %31
  %32 = icmp slt i64 %.1.us, %14
  %_QFEl._QFEx = select i1 %32, ptr @_QFEl, ptr @_QFEx
  %. = select i1 %32, i64 %19, i64 %17
  %.29 = select i1 %32, i64 %16, i64 %19
  store i64 %19, ptr %_QFEl._QFEx, align 8, !tbaa !3
  %33 = sub i64 %.29, %.
  %34 = icmp sgt i64 %33, 1
  br i1 %34, label %.lr.ph17.us, label %._crit_edge19

.lr.ph18.split:                                   ; preds = %.lr.ph18
  %35 = icmp sgt i64 %14, 0
  br i1 %35, label %.backedge.us20, label %.backedge

.backedge.us20:                                   ; preds = %.lr.ph18.split, %.backedge.us20
  %36 = phi i64 [ %38, %.backedge.us20 ], [ %_QFEl.promoted, %.lr.ph18.split ]
  %37 = add i64 %36, %_QFEx.promoted
  %38 = sdiv i64 %37, 2
  %39 = sub i64 %_QFEx.promoted, %38
  %40 = icmp sgt i64 %39, 1
  br i1 %40, label %.backedge.us20, label %._crit_edge19.split.split.us

._crit_edge19.split.split.us:                     ; preds = %.backedge.us20
  store i64 %38, ptr @_QFEl, align 8, !tbaa !3
  br label %._crit_edge19

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %41 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.01a115e2c0a779f2e82c1ff1d2bcd2be, i32 8)
  %42 = add nsw i64 %indvars.iv, -1
  %43 = getelementptr [100000 x i64], ptr @_QFEw, i64 0, i64 %42
  %44 = call i1 @_FortranAioInputInteger(ptr %41, ptr %43, i32 8)
  %45 = getelementptr [100000 x i64], ptr @_QFEd, i64 0, i64 %42
  %46 = call i1 @_FortranAioInputInteger(ptr %41, ptr %45, i32 8)
  %47 = call i32 @_FortranAioEndIoStatement(ptr %41)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %9
  br i1 %exitcond.not, label %.preheader, label %.lr.ph

.backedge:                                        ; preds = %.lr.ph18.split, %.backedge
  %48 = phi i64 [ %50, %.backedge ], [ %_QFEx.promoted, %.lr.ph18.split ]
  %49 = add i64 %_QFEl.promoted, %48
  %50 = sdiv i64 %49, 2
  %51 = sub i64 %50, %_QFEl.promoted
  %52 = icmp sgt i64 %51, 1
  br i1 %52, label %.backedge, label %._crit_edge19.split.split

._crit_edge19.split.split:                        ; preds = %.backedge
  store i64 %50, ptr @_QFEx, align 8, !tbaa !3
  br label %._crit_edge19

._crit_edge19:                                    ; preds = %._crit_edge.us, %._crit_edge19.split.split.us, %._crit_edge19.split.split, %.preheader
  %53 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.01a115e2c0a779f2e82c1ff1d2bcd2be, i32 23)
  %54 = load i64, ptr @_QFEx, align 8, !tbaa !3
  %55 = call i1 @_FortranAioOutputInteger64(ptr %53, i64 %54)
  %56 = call i32 @_FortranAioEndIoStatement(ptr %53)
  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

!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"}
