program abc145f
    implicit none
    integer N,K
    integer,allocatable::H(:)
    integer(16) ans
    integer(16),allocatable::DP(:,:)
    integer i,j,l

    read*,N,K
    allocate(H(0:N),DP(0:N,0:N))
    H(0)=0
    read*,H(1:N)
    DP=huge(dp)/2
    dp(0,0)=0
    do i=1,N
        do j=1,N
            do l=0,i-1
                dp(i,j)=min(dp(i,j),dp(l,j-1)+max(0,H(i)-H(l)))
            end do
        end do
    end do
    ans=huge(ans)
    do i=0,N
        ans=min(ans,dp(i,N-K))
    end do
    print"(i0)",ans
    
end program abc145f
; 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"

@_QFEdp.0 = internal unnamed_addr global ptr null
@_QFEdp.7 = internal unnamed_addr global i64 1
@_QFEdp.8 = internal unnamed_addr global i64 0
@_QFEdp.10 = internal unnamed_addr global i64 1
@_QFEdp.11 = internal unnamed_addr global i64 0
@_QFEh.0 = internal unnamed_addr global ptr null
@_QFEh.7 = internal unnamed_addr global i64 1
@_QQcl.57be1bb72cb7d683aae573b510be3576 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3013/source.f\00"
@_QQcl.16373402fa3425c6e46827601abb88fa = linkonce constant [76 x i8] c"array left hand side must be allocated when the right hand side is a scalar\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.57be1bb72cb7d683aae573b510be3576, i32 9)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %3, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 -1)
  %10 = sext i32 %9 to i64
  %11 = add nsw i64 %10, 1
  %12 = shl nuw nsw i64 %11, 2
  %13 = call ptr @malloc(i64 %12)
  %14 = icmp eq i64 %11, 0
  %.neg = sext i1 %14 to i64
  %15 = zext i1 %14 to i64
  store ptr %13, ptr @_QFEh.0, align 8, !tbaa !7
  store i64 %15, ptr @_QFEh.7, align 8, !tbaa !7
  %16 = shl nuw nsw i64 %11, 4
  %17 = mul i64 %16, %11
  %18 = call ptr @malloc(i64 %17)
  store ptr %18, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %15, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %11, ptr @_QFEdp.8, align 8, !tbaa !7
  store i64 %15, ptr @_QFEdp.10, align 8, !tbaa !7
  store i64 %11, ptr @_QFEdp.11, align 8, !tbaa !7
  %19 = getelementptr i32, ptr %13, i64 %.neg
  store i32 0, ptr %19, align 4, !tbaa !3
  %20 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.57be1bb72cb7d683aae573b510be3576, i32 12)
  %.unpack419 = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  %.unpack426.unpack.unpack = load i64, ptr @_QFEh.7, align 8, !tbaa !7
  %21 = load i32, ptr %3, align 4, !tbaa !3
  %22 = sub i64 1, %.unpack426.unpack.unpack
  %23 = call i32 @llvm.smax.i32(i32 %21, i32 0)
  %24 = zext i32 %23 to i64
  %25 = getelementptr i32, ptr %.unpack419, i64 %22
  store ptr %25, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %24, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %26 = call i1 @_FortranAioInputDescriptor(ptr %20, ptr nonnull %1)
  %27 = call i32 @_FortranAioEndIoStatement(ptr %20)
  %.unpack431 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack438.unpack.unpack441 = load i64, ptr @_QFEdp.8, align 8, !tbaa !7
  %.unpack438.unpack439.unpack444 = load i64, ptr @_QFEdp.11, align 8, !tbaa !7
  %.not = icmp eq ptr %.unpack431, null
  br i1 %.not, label %51, label %.preheader536

.preheader536:                                    ; preds = %0
  %28 = icmp sgt i64 %.unpack438.unpack439.unpack444, 0
  %29 = icmp sgt i64 %.unpack438.unpack.unpack441, 0
  %or.cond = select i1 %28, i1 %29, i1 false
  br i1 %or.cond, label %.preheader535.us.preheader, label %._crit_edge537._crit_edge562

.preheader535.us.preheader:                       ; preds = %.preheader536
  %xtraiter = and i64 %.unpack438.unpack.unpack441, 3
  %30 = icmp ult i64 %.unpack438.unpack.unpack441, 4
  %unroll_iter = and i64 %.unpack438.unpack.unpack441, -4
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader535.us

.preheader535.us:                                 ; preds = %.preheader535.us.preheader, %._crit_edge.us
  %31 = phi i64 [ %50, %._crit_edge.us ], [ 0, %.preheader535.us.preheader ]
  %32 = mul i64 %31, %.unpack438.unpack.unpack441
  br i1 %30, label %._crit_edge.us.unr-lcssa, label %.preheader535.us.new

.preheader535.us.new:                             ; preds = %.preheader535.us, %.preheader535.us.new
  %33 = phi i64 [ %43, %.preheader535.us.new ], [ 0, %.preheader535.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader535.us.new ], [ 0, %.preheader535.us ]
  %34 = or i64 %33, 1
  %35 = add i64 %33, %32
  %36 = getelementptr i128, ptr %.unpack431, i64 %35
  store i128 85070591730234615865843651857942052863, ptr %36, align 8, !tbaa !3
  %37 = or i64 %33, 2
  %38 = add i64 %34, %32
  %39 = getelementptr i128, ptr %.unpack431, i64 %38
  store i128 85070591730234615865843651857942052863, ptr %39, align 8, !tbaa !3
  %40 = or i64 %33, 3
  %41 = add i64 %37, %32
  %42 = getelementptr i128, ptr %.unpack431, i64 %41
  store i128 85070591730234615865843651857942052863, ptr %42, align 8, !tbaa !3
  %43 = add nuw nsw i64 %33, 4
  %44 = add i64 %40, %32
  %45 = getelementptr i128, ptr %.unpack431, i64 %44
  store i128 85070591730234615865843651857942052863, ptr %45, align 8, !tbaa !3
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader535.us.new

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader535.us.new, %.preheader535.us
  %.unr = phi i64 [ 0, %.preheader535.us ], [ %43, %.preheader535.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %46 = phi i64 [ %47, %.epil.preheader ], [ %.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %47 = add nuw nsw i64 %46, 1
  %48 = add i64 %46, %32
  %49 = getelementptr i128, ptr %.unpack431, i64 %48
  store i128 85070591730234615865843651857942052863, ptr %49, align 8, !tbaa !3
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !9

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %50 = add nuw i64 %31, 1
  %exitcond548.not = icmp eq i64 %50, %.unpack438.unpack439.unpack444
  br i1 %exitcond548.not, label %._crit_edge537._crit_edge562, label %.preheader535.us

._crit_edge537._crit_edge562:                     ; preds = %._crit_edge.us, %.preheader536
  %.unpack454.unpack.unpack.pre = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %.unpack454.unpack455.unpack.pre = load i64, ptr @_QFEdp.10, align 8, !tbaa !7
  br label %57

51:                                               ; preds = %0
  %52 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.57be1bb72cb7d683aae573b510be3576, i32 13)
  %.unpack514.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %.unpack514.unpack515.unpack = load i64, ptr @_QFEdp.10, align 8, !tbaa !7
  %53 = icmp eq i64 %.unpack438.unpack.unpack441, 0
  %54 = select i1 %53, i64 1, i64 %.unpack514.unpack.unpack
  %55 = icmp eq i64 %.unpack438.unpack439.unpack444, 0
  %56 = select i1 %55, i64 1, i64 %.unpack514.unpack515.unpack
  store ptr %.unpack431, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %54, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %.unpack438.unpack.unpack441, ptr @_QFEdp.8, align 8, !tbaa !7
  store i64 %56, ptr @_QFEdp.10, align 8, !tbaa !7
  store i64 %.unpack438.unpack439.unpack444, ptr @_QFEdp.11, align 8, !tbaa !7
  br label %57

57:                                               ; preds = %._crit_edge537._crit_edge562, %51
  %.unpack454.unpack455.unpack = phi i64 [ %.unpack454.unpack455.unpack.pre, %._crit_edge537._crit_edge562 ], [ %56, %51 ]
  %.unpack454.unpack.unpack = phi i64 [ %.unpack454.unpack.unpack.pre, %._crit_edge537._crit_edge562 ], [ %54, %51 ]
  %58 = mul i64 %.unpack454.unpack455.unpack, %.unpack438.unpack.unpack441
  %59 = add i64 %.unpack454.unpack.unpack, %58
  %60 = sub i64 0, %59
  %61 = getelementptr i128, ptr %.unpack431, i64 %60
  store i128 0, ptr %61, align 8, !tbaa !3
  %62 = load i32, ptr %3, align 4, !tbaa !3
  %63 = sext i32 %62 to i64
  %64 = icmp sgt i32 %62, 0
  br i1 %64, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %57
  %.unpack495 = load ptr, ptr @_QFEh.0, align 8
  %.unpack502.unpack.unpack = load i64, ptr @_QFEh.7, align 8
  %65 = xor i64 %.unpack454.unpack455.unpack, -1
  br label %.lr.ph.us.us.preheader

.lr.ph.us.us.preheader:                           ; preds = %.preheader.lr.ph, %._crit_edge539.us
  %indvars.iv550 = phi i64 [ %indvars.iv.next551, %._crit_edge539.us ], [ 1, %.preheader.lr.ph ]
  %66 = sub i64 %indvars.iv550, %.unpack454.unpack.unpack
  %67 = sub i64 %indvars.iv550, %.unpack502.unpack.unpack
  %68 = getelementptr i32, ptr %.unpack495, i64 %67
  br label %.lr.ph.us.us

._crit_edge539.us:                                ; preds = %._crit_edge.us540.us
  %indvars.iv.next551 = add nuw nsw i64 %indvars.iv550, 1
  %exitcond558.not = icmp eq i64 %indvars.iv550, %63
  br i1 %exitcond558.not, label %._crit_edge, label %.lr.ph.us.us.preheader

.lr.ph.us.us:                                     ; preds = %.lr.ph.us.us.preheader, %._crit_edge.us540.us
  %indvars.iv553 = phi i64 [ 1, %.lr.ph.us.us.preheader ], [ %indvars.iv.next554, %._crit_edge.us540.us ]
  %69 = sub i64 %indvars.iv553, %.unpack454.unpack455.unpack
  %70 = mul i64 %69, %.unpack438.unpack.unpack441
  %71 = add i64 %66, %70
  %72 = getelementptr i128, ptr %.unpack431, i64 %71
  %73 = add i64 %indvars.iv553, %65
  %74 = mul i64 %73, %.unpack438.unpack.unpack441
  %75 = sub i64 %74, %.unpack454.unpack.unpack
  %.pre = load i128, ptr %72, align 8, !tbaa !3
  br label %76

76:                                               ; preds = %76, %.lr.ph.us.us
  %77 = phi i128 [ %89, %76 ], [ %.pre, %.lr.ph.us.us ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %76 ], [ 0, %.lr.ph.us.us ]
  %78 = add i64 %75, %indvars.iv
  %79 = getelementptr i128, ptr %.unpack431, i64 %78
  %80 = load i128, ptr %79, align 8, !tbaa !3
  %81 = load i32, ptr %68, align 4, !tbaa !3
  %82 = sub i64 %indvars.iv, %.unpack502.unpack.unpack
  %83 = getelementptr i32, ptr %.unpack495, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !3
  %85 = sub i32 %81, %84
  %86 = call i32 @llvm.smax.i32(i32 %85, i32 0)
  %87 = zext i32 %86 to i128
  %88 = add i128 %80, %87
  %89 = call i128 @llvm.smin.i128(i128 %77, i128 %88)
  store i128 %89, ptr %72, align 8, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond552.not = icmp eq i64 %indvars.iv.next, %indvars.iv550
  br i1 %exitcond552.not, label %._crit_edge.us540.us, label %76

._crit_edge.us540.us:                             ; preds = %76
  %indvars.iv.next554 = add nuw nsw i64 %indvars.iv553, 1
  %exitcond556.not = icmp eq i64 %indvars.iv553, %63
  br i1 %exitcond556.not, label %._crit_edge539.us, label %.lr.ph.us.us

._crit_edge:                                      ; preds = %._crit_edge539.us, %57
  %90 = icmp sgt i32 %62, -1
  br i1 %90, label %.lr.ph, label %._crit_edge545

.lr.ph:                                           ; preds = %._crit_edge
  %91 = add nsw i64 %63, 1
  %92 = load i32, ptr %2, align 4, !tbaa !3
  %93 = sub i32 %62, %92
  %94 = sext i32 %93 to i64
  %95 = sub i64 %94, %.unpack454.unpack455.unpack
  %96 = mul i64 %95, %.unpack438.unpack.unpack441
  br label %97

97:                                               ; preds = %.lr.ph, %97
  %indvars.iv559 = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next560, %97 ]
  %98 = phi i64 [ %91, %.lr.ph ], [ %104, %97 ]
  %.0543 = phi i128 [ 170141183460469231731687303715884105727, %.lr.ph ], [ %103, %97 ]
  %99 = sub i64 %indvars.iv559, %.unpack454.unpack.unpack
  %100 = add i64 %99, %96
  %101 = getelementptr i128, ptr %.unpack431, i64 %100
  %102 = load i128, ptr %101, align 8, !tbaa !3
  %103 = call i128 @llvm.smin.i128(i128 %.0543, i128 %102)
  %indvars.iv.next560 = add nuw nsw i64 %indvars.iv559, 1
  %104 = add nsw i64 %98, -1
  %105 = icmp sgt i64 %98, 1
  br i1 %105, label %97, label %._crit_edge545

._crit_edge545:                                   ; preds = %97, %._crit_edge
  %.0.lcssa = phi i128 [ 170141183460469231731687303715884105727, %._crit_edge ], [ %103, %97 ]
  %106 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.57be1bb72cb7d683aae573b510be3576, i32 26)
  %107 = call i1 @_FortranAioOutputInteger128(ptr %106, i128 %.0.lcssa)
  %108 = call i32 @_FortranAioEndIoStatement(ptr %106)
  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 i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare {} @_FortranAReportFatalUserError(ptr, ptr, i32) 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
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 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
