from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

global n,k
global ws

def iSok(Pmax):
    truck = 0
    now = 0
    for i in range(n):
        if ws[i]>Pmax:
            return False
        if now+ws[i]>Pmax:
            truck += 1
            now = ws[i]
        else:
            now += ws[i]
    if now > 0:
        truck += 1
    if truck > k:
        return False
    else:
        return True

n,k = map(int,input().split())

now = 0
ws = [int(input()) for i in range(n)]
amin = 0
amax = sum(ws)

while amax-amin >1:
    amid = (amin + amax)//2
    if iSok(amid):
        amax = amid
    else:
        amin = amid
print(amax)
 from enum import Enum from queue import Queue import collections collections import sys sys import math math BIG_NUM = 2000000000 BIG_NUM 2000000000 MOD = 1000000007 MOD 1000000007 EPS = 0.000000001 EPS 0.000000001 global n,k global ws def iSok(Pmax):
    truck = 0
    now = 0
    for i in range(n):
        if ws[i]>Pmax:
            return False
        if now+ws[i]>Pmax:
            truck += 1
            now = ws[i]
        else:
            now += ws[i]
    if now > 0:
        truck += 1
    if truck > k:
        return False
    else:
        return True iSok truck = 0 truck 0 now = 0 now 0 for i in range(n):
        if ws[i]>Pmax:
            return False
        if now+ws[i]>Pmax:
            truck += 1
            now = ws[i]
        else:
            now += ws[i]
     i range(n) range n if ws[i]>Pmax:
            return False
         ws[i]>Pmax ws[i] ws i Pmax return False False if now+ws[i]>Pmax:
            truck += 1
            now = ws[i]
        else:
            now += ws[i]
     now+ws[i]>Pmax now+ws[i] now ws[i] ws i Pmax truck += 1 truck 1 now = ws[i] now ws[i] ws i now += ws[i] now ws[i] ws i if now > 0:
        truck += 1
     now > 0 now 0 truck += 1 truck 1 if truck > k:
        return False
    else:
        return True truck > k truck k return False False return True True Pmax Pmax n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k now = 0 now 0 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 ws = [int(input()) for i in range(n)] ws [int(input()) for i in range(n)] amin = 0 amin 0 amax = sum(ws) amax sum(ws) sum ws while amax-amin >1:
    amid = (amin + amax)//2
    if iSok(amid):
        amax = amid
    else:
        amin = amid amax-amin >1 amax-amin amax amin 1 amid = (amin + amax)//2 amid (amin + amax)//2 amin + amax amin amax 2 if iSok(amid):
        amax = amid
    else:
        amin = amid iSok(amid) iSok amid amax = amid amax amid amin = amid amin amid print(amax) print amax global n,k amid = (amin + amax)//2 (amin + amax)//2 amid ws = [int(input()) for i in range(n)] [int(input()) for i in range(n)] ws amax = amid amid amax BIG_NUM = 2000000000 2000000000 BIG_NUM amin = 0 0 amin MOD = 1000000007 1000000007 MOD def iSok(Pmax):
    truck = 0
    now = 0
    for i in range(n):
        if ws[i]>Pmax:
            return False
        if now+ws[i]>Pmax:
            truck += 1
            now = ws[i]
        else:
            now += ws[i]
    if now > 0:
        truck += 1
    if truck > k:
        return False
    else:
        return True def iSok(Pmax):
    truck = 0
    now = 0
    for i in range(n):
        if ws[i]>Pmax:
            return False
        if now+ws[i]>Pmax:
            truck += 1
            now = ws[i]
        else:
            now += ws[i]
    if now > 0:
        truck += 1
    if truck > k:
        return False
    else:
        return True iSok now = 0 0 now EPS = 0.000000001 0.000000001 EPS global ws n,k = map(int,input().split()) map(int,input().split()) n amax = sum(ws) sum(ws) amax k = map(int,input().split()) map(int,input().split()) k amin = amid amid amin
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

global n,k
global ws

def iSok(Pmax):
    truck = 0
    now = 0
    for i in range(n):
        if ws[i]>Pmax:
            return False
        if now+ws[i]>Pmax:
            truck += 1
            now = ws[i]
        else:
            now += ws[i]
    if now > 0:
        truck += 1
    if truck > k:
        return False
    else:
        return True

n,k = map(int,input().split())

now = 0
ws = [int(input()) for i in range(n)]
amin = 0
amax = sum(ws)

while amax-amin >1:
    amid = (amin + amax)//2
    if iSok(amid):
        amax = amid
    else:
        amin = amid
print(amax)

