program sum_and_subarray
  implicit none
  integer(8)              :: n, k, s, i, j, l
  integer(8), allocatable :: a(:), m(:)
  read(*,*) n, k
  s = n*(n+1)/2
  allocate(a(n),m(s))
  read(*,*) a(:)

  l = 0
  do i = 0, n-1
     do j = 1, n-i
        l = l + 1
        m(l) = sum(a(j:j+i))
     end do
  end do
  call merge_sort(s,m)
  write(*,'(i0)') m(s-k+1)
  deallocate(a,m)
  stop

contains

  subroutine merge_sort(n,c)
    implicit none
    integer(8), intent(in)    :: n
    integer(8), intent(inout) :: c(n)
    integer(8)                :: number, length, i, ubound
    number = n
    length = 1
    do while (number .gt. 1)
       do i = 1, number/2
          ubound = min(2*i*length,n)
          call merge(c(2*(i-1)*length+1:(2*i-1)*length),c((2*i-1)*length+1:ubound))
       end do
       length = 2*length
       number = (number+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merge(c1,c2)
    implicit none
    integer(8), intent(inout) :: c1(:), c2(:)
    integer(8)                :: c(size(c1)+size(c2))
    integer(8)                :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1)
    n2 = size(c2)
    do while (i1 .le. n1 .and. i2 .le. n2)
       if (c1(i1) .lt. c2(i2)) then
          c(i1+i2-1) = c1(i1)
          i1 = i1+1
       else
          c(i1+i2-1) = c2(i2)
          i2 = i2+1
       end if
    end do
    if (i1 .le. n1) then
       c(i1+i2-1:n1+n2) = c1(i1:n1)
    else if (i2 .le. n2) then
       c(i1+i2-1:n1+n2) = c2(i2:n2)
    end if
    c1 = c(1:n1)
    c2 = c(n1+1:n1+n2)
    return
  end subroutine merge
  
end program sum_and_subarray