from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break from collections import deque def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True isPa tr = 0 tr 0 c = 0 c 0 d = deque(w) d deque(w) deque w while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
     d tmp = d.popleft() tmp d.popleft() d.popleft d popleft if(tmp > p):
            return False
        
         tmp > p tmp p return False False if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
         tr + tmp > p tr + tmp tr tmp p tr = tmp tr tmp c += 1 c 1 tr += tmp tr tmp if c+1>k:
            return False
     c+1>k c+1 c 1 k return False False return True True w w k k p p def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp MaxInP maxinp = 0 maxinp 0 tmp = 0 tmp 0 d = deque(w) d deque(w) deque w while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
     d tmp += d.popleft() tmp d.popleft() d.popleft d popleft if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
     tmp > p tmp p if(tmp > maxinp):
                maxinp = tmp
             tmp > maxinp tmp maxinp maxinp = tmp maxinp tmp tmp = 0 tmp 0 return maxinp maxinp w w k k p p int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n,k = [int(x) for x in input().split()] n [int(x) for x in input().split()] k w = deque() w deque() deque 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 mean = int(sum(w)/k) mean int(sum(w)/k) int sum(w)/k sum(w) sum w k maxinp = MaxInP(w,k,mean) maxinp MaxInP(w,k,mean) MaxInP w k mean if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break k == 1 k 1 print(mean) print mean minP = mean minP mean maxP = maxinp maxP maxinp while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break True m = int ((minP + maxP)/2) m int ((minP + maxP)/2) int (minP + maxP)/2 minP + maxP minP maxP 2 if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
         isPa(w,k,m) isPa w k m maxP = m maxP m minP = m minP m if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break minP+1 == maxP or minP == maxP minP+1 == maxP minP+1 minP 1 maxP minP == maxP minP maxP print(maxP) print maxP break k = [int(x) for x in input().split()] [int(x) for x in input().split()] k minP = mean mean minP m = int ((minP + maxP)/2) int ((minP + maxP)/2) m minP = m m minP def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp MaxInP def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True isPa n,k = [int(x) for x in input().split()] [int(x) for x in input().split()] n maxP = maxinp maxinp maxP maxinp = MaxInP(w,k,mean) MaxInP(w,k,mean) maxinp mean = int(sum(w)/k) int(sum(w)/k) mean maxP = m m maxP w = deque() deque() w
from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break