

def p(k,w,maxP):
    count = 1
    tmpWeight = 0
    for x in w:
        if tmpWeight+x <= maxP:
            tmpWeight += x
        else:
            count += 1
            if count > k :
                return False
            tmpWeight = x
    

    return True




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


w = []

for _ in range(n):
    w.append((int)(input()))
rangeMax = sum(w)
rangeMin = max(w)
rangeMid = 0
while rangeMin < rangeMax:
    rangeMid = (rangeMax + rangeMin)//2
    '''print(p(k,w,rangeMid))
    print(p(k,w,rangeMid+1))
    print("---")
    '''
    if p(k,w,rangeMid) == True:
        rangeMax = rangeMid
    else:
        rangeMid += 1
        rangeMin = rangeMid

print(rangeMid) def p(k,w,maxP):
    count = 1
    tmpWeight = 0
    for x in w:
        if tmpWeight+x <= maxP:
            tmpWeight += x
        else:
            count += 1
            if count > k :
                return False
            tmpWeight = x
    

    return True p count = 1 count 1 tmpWeight = 0 tmpWeight 0 for x in w:
        if tmpWeight+x <= maxP:
            tmpWeight += x
        else:
            count += 1
            if count > k :
                return False
            tmpWeight = x
    

     x w if tmpWeight+x <= maxP:
            tmpWeight += x
        else:
            count += 1
            if count > k :
                return False
            tmpWeight = x
    

     tmpWeight+x <= maxP tmpWeight+x tmpWeight x maxP tmpWeight += x tmpWeight x count += 1 count 1 if count > k :
                return False
             count > k count k return False False tmpWeight = x tmpWeight x return True True k k w w maxP maxP 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 rangeMax = sum(w) rangeMax sum(w) sum w rangeMin = max(w) rangeMin max(w) max w rangeMid = 0 rangeMid 0 while rangeMin < rangeMax:
    rangeMid = (rangeMax + rangeMin)//2
    '''print(p(k,w,rangeMid))
    print(p(k,w,rangeMid+1))
    print("---")
    '''
    if p(k,w,rangeMid) == True:
        rangeMax = rangeMid
    else:
        rangeMid += 1
        rangeMin = rangeMid rangeMin < rangeMax rangeMin rangeMax rangeMid = (rangeMax + rangeMin)//2 rangeMid (rangeMax + rangeMin)//2 rangeMax + rangeMin rangeMax rangeMin 2 '''print(p(k,w,rangeMid))
    print(p(k,w,rangeMid+1))
    print("---")
    ''' if p(k,w,rangeMid) == True:
        rangeMax = rangeMid
    else:
        rangeMid += 1
        rangeMin = rangeMid p(k,w,rangeMid) == True p(k,w,rangeMid) p k w rangeMid True rangeMax = rangeMid rangeMax rangeMid rangeMid += 1 rangeMid 1 rangeMin = rangeMid rangeMin rangeMid print(rangeMid) print rangeMid n,k = map(int,input().split()) map(int,input().split()) n w = [] [] w rangeMax = sum(w) sum(w) rangeMax rangeMid = (rangeMax + rangeMin)//2 (rangeMax + rangeMin)//2 rangeMid rangeMax = rangeMid rangeMid rangeMax k = map(int,input().split()) map(int,input().split()) k rangeMid = 0 0 rangeMid def p(k,w,maxP):
    count = 1
    tmpWeight = 0
    for x in w:
        if tmpWeight+x <= maxP:
            tmpWeight += x
        else:
            count += 1
            if count > k :
                return False
            tmpWeight = x
    

    return True def p(k,w,maxP):
    count = 1
    tmpWeight = 0
    for x in w:
        if tmpWeight+x <= maxP:
            tmpWeight += x
        else:
            count += 1
            if count > k :
                return False
            tmpWeight = x
    

    return True p rangeMin = max(w) max(w) rangeMin rangeMid += 1 1 rangeMid rangeMin = rangeMid rangeMid rangeMin


def p(k,w,maxP):
    count = 1
    tmpWeight = 0
    for x in w:
        if tmpWeight+x <= maxP:
            tmpWeight += x
        else:
            count += 1
            if count > k :
                return False
            tmpWeight = x
    

    return True




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


w = []

for _ in range(n):
    w.append((int)(input()))
rangeMax = sum(w)
rangeMin = max(w)
rangeMid = 0
while rangeMin < rangeMax:
    rangeMid = (rangeMax + rangeMin)//2
    '''print(p(k,w,rangeMid))
    print(p(k,w,rangeMid+1))
    print("---")
    '''
    if p(k,w,rangeMid) == True:
        rangeMax = rangeMid
    else:
        rangeMid += 1
        rangeMin = rangeMid

print(rangeMid)