# -*- coding: utf-8 -*-
"""
Created on Mon Apr 30 15:18:29 2018
ALDS1-4c
@author: maezawa
"""
def can_load(w, k, p):
    n = len(w)
    m = 0
    tk = 0
    i = 0
    while tk < k:
        if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
    return i


n, k = list(map(int, input().split()))
w = []
tr = [0 for _ in range(k)]

for i in range(n):
    w.append(int(input()))

maxw = max(w)
# =============================================================================
# for p in range(maxw, maxw*n):
#     if can_load(w, k, p) == n:
#         print(p)
#         break
# =============================================================================
right = maxw*n
left = maxw
while left<right:
    mid = (right+left)//2
    cl = can_load(w, k, mid)
#    if cl == n:
#        print(mid)
#        break
#    elif cl < n:
    if cl < n:
        left = mid + 1
    else:
        right = mid
print(right)    
    
    
    
    
     """
Created on Mon Apr 30 15:18:29 2018
ALDS1-4c
@author: maezawa
""" def can_load(w, k, p):
    n = len(w)
    m = 0
    tk = 0
    i = 0
    while tk < k:
        if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
    return i can_load n = len(w) n len(w) len w m = 0 m 0 tk = 0 tk 0 i = 0 i 0 while tk < k:
        if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
     tk < k tk k if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
     m + w[i] <= p m + w[i] m w[i] w i p m += w[i] m w[i] w i i += 1 i 1 if i >= n:
                return n+1
         i >= n i n return n+1 n+1 n 1 m = 0 m 0 tk += 1 tk 1 return i i w w k k p p n, k = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k w = [] w [] 0 for _ in range(k) for _ in range(k) _ range(k) range k for _ in range(k) 0 tr = [0 for _ in range(k)] tr [0 for _ in range(k)] for i in range(n):
    w.append(int(input())) i range(n) range n w.append(int(input())) w.append w append int(input()) int input() input maxw = max(w) maxw max(w) max w right = maxw*n right maxw*n maxw n left = maxw left maxw while left<right:
    mid = (right+left)//2
    cl = can_load(w, k, mid)
#    if cl == n:
#        print(mid)
#        break
#    elif cl < n:
    if cl < n:
        left = mid + 1
    else:
        right = mid left<right left right mid = (right+left)//2 mid (right+left)//2 right+left right left 2 cl = can_load(w, k, mid) cl can_load(w, k, mid) can_load w k mid if cl < n:
        left = mid + 1
    else:
        right = mid cl < n cl n left = mid + 1 left mid + 1 mid 1 right = mid right mid print(right) print right k = list(map(int, input().split())) list(map(int, input().split())) k right = maxw*n maxw*n right mid = (right+left)//2 (right+left)//2 mid tr = [0 for _ in range(k)] [0 for _ in range(k)] tr n, k = list(map(int, input().split())) list(map(int, input().split())) n maxw = max(w) max(w) maxw cl = can_load(w, k, mid) can_load(w, k, mid) cl w = [] [] w left = maxw maxw left def can_load(w, k, p):
    n = len(w)
    m = 0
    tk = 0
    i = 0
    while tk < k:
        if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
    return i def can_load(w, k, p):
    n = len(w)
    m = 0
    tk = 0
    i = 0
    while tk < k:
        if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
    return i can_load left = mid + 1 mid + 1 left right = mid mid right
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 30 15:18:29 2018
ALDS1-4c
@author: maezawa
"""
def can_load(w, k, p):
    n = len(w)
    m = 0
    tk = 0
    i = 0
    while tk < k:
        if m + w[i] <= p:
            m += w[i]
            i += 1
            if i >= n:
                return n+1
        else:
            m = 0
            tk += 1
    return i


n, k = list(map(int, input().split()))
w = []
tr = [0 for _ in range(k)]

for i in range(n):
    w.append(int(input()))

maxw = max(w)
# =============================================================================
# for p in range(maxw, maxw*n):
#     if can_load(w, k, p) == n:
#         print(p)
#         break
# =============================================================================
right = maxw*n
left = maxw
while left<right:
    mid = (right+left)//2
    cl = can_load(w, k, mid)
#    if cl == n:
#        print(mid)
#        break
#    elif cl < n:
    if cl < n:
        left = mid + 1
    else:
        right = mid
print(right)    
    
    
    
    
    
