n,t=[int(x) for x in input().split()]
w=[]
for i in range(n):
    w.append(int(input()))

totalw=sum(w)  
pmax=totalw
pmin=int(totalw/t)-1

def check(ptest):
    tk=1
    p=0
    global t
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>t:
            return 0
            #break   
    
    return 1
    
        
while (pmax-pmin)>1:
    pmid=(pmax+pmin)//2
    if check(pmid)==1:
        pmax=pmid
    else:
        pmin=pmid
        
print(pmax) 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,t=[int(x) for x in input().split()] n [int(x) for x in input().split()] t w=[] w [] 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 totalw=sum(w) totalw sum(w) sum w pmax=totalw pmax totalw pmin=int(totalw/t)-1 pmin int(totalw/t)-1 int(totalw/t) int totalw/t totalw t 1 def check(ptest):
    tk=1
    p=0
    global t
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>t:
            return 0
            #break   
    
    return 1
    
         check tk=1 tk 1 p=0 p 0 global t global w global n i=0 i 0 while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>t:
            return 0
            #break   
    
     i<n i n p+=w[i] p w[i] w i if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
         p<=ptest p ptest i+=1 i 1 tk+=1 tk 1 p=0 p 0 if tk>t:
            return 0
            #break   
    
     tk>t tk t return 0 0 return 1 1 ptest ptest while (pmax-pmin)>1:
    pmid=(pmax+pmin)//2
    if check(pmid)==1:
        pmax=pmid
    else:
        pmin=pmid
         (pmax-pmin)>1 pmax-pmin pmax pmin 1 pmid=(pmax+pmin)//2 pmid (pmax+pmin)//2 pmax+pmin pmax pmin 2 if check(pmid)==1:
        pmax=pmid
    else:
        pmin=pmid
         check(pmid)==1 check(pmid) check pmid 1 pmax=pmid pmax pmid pmin=pmid pmin pmid print(pmax) print pmax pmax=totalw totalw pmax totalw=sum(w) sum(w) totalw n,t=[int(x) for x in input().split()] [int(x) for x in input().split()] n t=[int(x) for x in input().split()] [int(x) for x in input().split()] t pmax=pmid pmid pmax pmin=int(totalw/t)-1 int(totalw/t)-1 pmin def check(ptest):
    tk=1
    p=0
    global t
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>t:
            return 0
            #break   
    
    return 1
    
         def check(ptest):
    tk=1
    p=0
    global t
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>t:
            return 0
            #break   
    
    return 1
    
         check pmid=(pmax+pmin)//2 (pmax+pmin)//2 pmid w=[] [] w pmin=pmid pmid pmin
n,t=[int(x) for x in input().split()]
w=[]
for i in range(n):
    w.append(int(input()))

totalw=sum(w)  
pmax=totalw
pmin=int(totalw/t)-1

def check(ptest):
    tk=1
    p=0
    global t
    global w
    global n
    i=0
    
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
            
        if tk>t:
            return 0
            #break   
    
    return 1
    
        
while (pmax-pmin)>1:
    pmid=(pmax+pmin)//2
    if check(pmid)==1:
        pmax=pmid
    else:
        pmin=pmid
        
print(pmax)
