program ABC061C
    implicit none
    integer(8)::N,K,a,b,i,count
    integer(8),dimension(100000)::L
    read(5,*)N,K
    L=0
    count=0

    do i=1,N
        read(5,*)a,b
        L(a)=L(a)+b
    end do

    do i=1,100000
        count=count+L(i)
        if(count>=K)then
            print'(i0)',i
            exit
        end if
    end do
end program ABC061C
; 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"

@_QFEl = internal unnamed_addr global [100000 x i64] undef
@_QQcl.7062be94954bbd17f409c1ec4f835ffa = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7298/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 i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.7062be94954bbd17f409c1ec4f835ffa, i32 5)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %4, i32 8)
  %7 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %3, i32 8)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %5)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) @_QFEl, i8 0, i64 800000, i1 false), !tbaa !3
  %9 = load i64, ptr %4, align 8, !tbaa !3
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %0
  %11 = load i64, ptr %3, align 8, !tbaa !3
  br label %25

.lr.ph:                                           ; preds = %0, %.lr.ph
  %12 = phi i64 [ %23, %.lr.ph ], [ %9, %0 ]
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.7062be94954bbd17f409c1ec4f835ffa, i32 10)
  %14 = call i1 @_FortranAioInputInteger(ptr %13, ptr nonnull %1, i32 8)
  %15 = call i1 @_FortranAioInputInteger(ptr %13, ptr nonnull %2, i32 8)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %17 = load i64, ptr %1, align 8, !tbaa !3
  %18 = add i64 %17, -1
  %19 = getelementptr [100000 x i64], ptr @_QFEl, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !3
  %21 = load i64, ptr %2, align 8, !tbaa !3
  %22 = add i64 %21, %20
  store i64 %22, ptr %19, align 8, !tbaa !3
  %23 = add nsw i64 %12, -1
  %24 = icmp ugt i64 %12, 1
  br i1 %24, label %.lr.ph, label %.preheader

25:                                               ; preds = %38, %.preheader
  %.016 = phi i64 [ 1, %.preheader ], [ %39, %38 ]
  %.0815 = phi i64 [ 0, %.preheader ], [ %37, %38 ]
  %26 = add nsw i64 %.016, -1
  %27 = getelementptr [100000 x i64], ptr @_QFEl, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !3
  %29 = add i64 %28, %.0815
  %.not = icmp slt i64 %29, %11
  br i1 %.not, label %34, label %.split.loop.exit21

.split.loop.exit:                                 ; preds = %34
  %30 = add nuw nsw i64 %.016, 1
  br label %.split.loop.exit21

.split.loop.exit21:                               ; preds = %25, %.split.loop.exit
  %.016.lcssa = phi i64 [ %30, %.split.loop.exit ], [ %.016, %25 ]
  %31 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.7062be94954bbd17f409c1ec4f835ffa, i32 17)
  %32 = call i1 @_FortranAioOutputInteger64(ptr %31, i64 %.016.lcssa)
  %33 = call i32 @_FortranAioEndIoStatement(ptr %31)
  br label %.loopexit

34:                                               ; preds = %25
  %35 = getelementptr [100000 x i64], ptr @_QFEl, i64 0, i64 %.016
  %36 = load i64, ptr %35, align 8, !tbaa !3
  %37 = add i64 %36, %29
  %.not.1 = icmp slt i64 %37, %11
  br i1 %.not.1, label %38, label %.split.loop.exit

38:                                               ; preds = %34
  %39 = add nuw nsw i64 %.016, 2
  %exitcond.not.1 = icmp eq i64 %39, 100001
  br i1 %exitcond.not.1, label %.loopexit, label %25

.loopexit:                                        ; preds = %38, %.split.loop.exit21
  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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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