import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N,K = map(int,input().split())
W = []
for _ in range(N):
    W.append(int(input()))


def is_OK(P):
    track_index = 0
    w_index = 0
    while w_index < N and track_index < K:
        tmp_sum = 0
        while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
        track_index += 1
    return w_index == N

L = 0
R = 100000*100000
mid = (L+R)//2
ans = R

while L <= R:
    if is_OK(mid):
        ans = mid
        R = mid-1
    else:
        L = mid+1
    mid = (L+R)//2

print("%d"%ans)

 import heapq heapq from collections import deque from enum import Enum import sys sys import math math from _heapq import heappush, heappop BIG_NUM = 2000000000 BIG_NUM 2000000000 MOD = 1000000007 MOD 1000000007 EPS = 0.000000001 EPS 0.000000001 N,K = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K W = [] W [] for _ in range(N):
    W.append(int(input())) _ range(N) range N W.append(int(input())) W.append W append int(input()) int input() input def is_OK(P):
    track_index = 0
    w_index = 0
    while w_index < N and track_index < K:
        tmp_sum = 0
        while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
        track_index += 1
    return w_index == N is_OK track_index = 0 track_index 0 w_index = 0 w_index 0 while w_index < N and track_index < K:
        tmp_sum = 0
        while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
        track_index += 1
     w_index < N and track_index < K w_index < N w_index N track_index < K track_index K tmp_sum = 0 tmp_sum 0 while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
         w_index < N and tmp_sum+W[w_index] <= P w_index < N w_index N tmp_sum+W[w_index] <= P tmp_sum+W[w_index] tmp_sum W[w_index] W w_index P tmp_sum += W[w_index] tmp_sum W[w_index] W w_index w_index += 1 w_index 1 track_index += 1 track_index 1 return w_index == N w_index == N w_index N P P L = 0 L 0 R = 100000*100000 R 100000*100000 100000 100000 mid = (L+R)//2 mid (L+R)//2 L+R L R 2 ans = R ans R while L <= R:
    if is_OK(mid):
        ans = mid
        R = mid-1
    else:
        L = mid+1
    mid = (L+R)//2 L <= R L R if is_OK(mid):
        ans = mid
        R = mid-1
    else:
        L = mid+1
     is_OK(mid) is_OK mid ans = mid ans mid R = mid-1 R mid-1 mid 1 L = mid+1 L mid+1 mid 1 mid = (L+R)//2 mid (L+R)//2 L+R L R 2 print("%d"%ans) print "%d"%ans "%d" ans K = map(int,input().split()) map(int,input().split()) K def is_OK(P):
    track_index = 0
    w_index = 0
    while w_index < N and track_index < K:
        tmp_sum = 0
        while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
        track_index += 1
    return w_index == N def is_OK(P):
    track_index = 0
    w_index = 0
    while w_index < N and track_index < K:
        tmp_sum = 0
        while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
        track_index += 1
    return w_index == N is_OK R = 100000*100000 100000*100000 R EPS = 0.000000001 0.000000001 EPS BIG_NUM = 2000000000 2000000000 BIG_NUM MOD = 1000000007 1000000007 MOD N,K = map(int,input().split()) map(int,input().split()) N L = 0 0 L ans = mid mid ans R = mid-1 mid-1 R L = mid+1 mid+1 L ans = R R ans W = [] [] W mid = (L+R)//2 (L+R)//2 mid mid = (L+R)//2 (L+R)//2 mid
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N,K = map(int,input().split())
W = []
for _ in range(N):
    W.append(int(input()))


def is_OK(P):
    track_index = 0
    w_index = 0
    while w_index < N and track_index < K:
        tmp_sum = 0
        while  w_index < N and tmp_sum+W[w_index] <= P:
            tmp_sum += W[w_index]
            w_index += 1
        track_index += 1
    return w_index == N

L = 0
R = 100000*100000
mid = (L+R)//2
ans = R

while L <= R:
    if is_OK(mid):
        ans = mid
        R = mid-1
    else:
        L = mid+1
    mid = (L+R)//2

print("%d"%ans)


