def main():
    N, K = (int(i) for i in input().split())
    w = [int(input()) for i in range(N)]
    S = 0
    for i in range(N):
        S += w[i]

    def is_ok(P):
        w_i = 0
        for i in range(K):
            cur = 0
            while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
        if w_i == N:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = S + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid): 
                right = mid
            else: 
                left = mid
        return right
    
    print(binary_search_meguru())


if __name__ == '__main__':
    main() def main():
    N, K = (int(i) for i in input().split())
    w = [int(input()) for i in range(N)]
    S = 0
    for i in range(N):
        S += w[i]

    def is_ok(P):
        w_i = 0
        for i in range(K):
            cur = 0
            while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
        if w_i == N:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = S + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid): 
                right = mid
            else: 
                left = mid
        return right
    
    print(binary_search_meguru()) main int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i N, K = (int(i) for i in input().split()) N (int(i) for i in input().split()) K int(input()) for i in range(N) for i in range(N) i range(N) range N for i in range(N) int(input()) int input() input w = [int(input()) for i in range(N)] w [int(input()) for i in range(N)] S = 0 S 0 for i in range(N):
        S += w[i]

     i range(N) range N S += w[i] S w[i] w i def is_ok(P):
        w_i = 0
        for i in range(K):
            cur = 0
            while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
        if w_i == N:
            return True
        else:
            return False

     is_ok w_i = 0 w_i 0 for i in range(K):
            cur = 0
            while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
         i range(K) range K cur = 0 cur 0 while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
         w_i < N w_i N if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
         cur + w[w_i] <= P cur + w[w_i] cur w[w_i] w w_i P cur += w[w_i] cur w[w_i] w w_i w_i += 1 w_i 1 break if w_i == N:
            return True
        else:
            return False

     w_i == N w_i N return True True return False False P P def binary_search_meguru():
        left = -1
        right = S + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid): 
                right = mid
            else: 
                left = mid
        return right
    
     binary_search_meguru left = -1 left -1 right = S + 1 right S + 1 S 1 while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid): 
                right = mid
            else: 
                left = mid
         right - left > 1 right - left right left 1 mid = left + ((right - left) // 2) mid left + ((right - left) // 2) left (right - left) // 2 right - left right left 2 if is_ok(mid): 
                right = mid
            else: 
                left = mid
         is_ok(mid) is_ok mid right = mid right mid left = mid left mid return right right print(binary_search_meguru()) print binary_search_meguru() binary_search_meguru if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N, K = (int(i) for i in input().split())
    w = [int(input()) for i in range(N)]
    S = 0
    for i in range(N):
        S += w[i]

    def is_ok(P):
        w_i = 0
        for i in range(K):
            cur = 0
            while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
        if w_i == N:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = S + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid): 
                right = mid
            else: 
                left = mid
        return right
    
    print(binary_search_meguru()) def main():
    N, K = (int(i) for i in input().split())
    w = [int(input()) for i in range(N)]
    S = 0
    for i in range(N):
        S += w[i]

    def is_ok(P):
        w_i = 0
        for i in range(K):
            cur = 0
            while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
        if w_i == N:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = S + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid): 
                right = mid
            else: 
                left = mid
        return right
    
    print(binary_search_meguru()) main
def main():
    N, K = (int(i) for i in input().split())
    w = [int(input()) for i in range(N)]
    S = 0
    for i in range(N):
        S += w[i]

    def is_ok(P):
        w_i = 0
        for i in range(K):
            cur = 0
            while w_i < N :
                if cur + w[w_i] <= P:
                    cur += w[w_i]
                    w_i += 1
                else:
                    break
        if w_i == N:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = S + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid): 
                right = mid
            else: 
                left = mid
        return right
    
    print(binary_search_meguru())


if __name__ == '__main__':
    main()
