import sys

def binarySearch(t,w):
    left = max(w)
    right = sum(w)
    while left < right:
        middle = (left + right) // 2
        if hantei(t,w,middle):
            right = middle 
        else:
            left = middle + 1
    return left
            
def hantei(t,w,p):
    track_on = 0
    daisu = 1
    for j in range(len(w)):     
        track_on += w[j]
        if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
    return True


nimotsu, track = map(int,input().split())
weight = list(map(int,sys.stdin.readlines()))



print(binarySearch(track,weight)) import sys sys def binarySearch(t,w):
    left = max(w)
    right = sum(w)
    while left < right:
        middle = (left + right) // 2
        if hantei(t,w,middle):
            right = middle 
        else:
            left = middle + 1
    return left
             binarySearch left = max(w) left max(w) max w right = sum(w) right sum(w) sum w while left < right:
        middle = (left + right) // 2
        if hantei(t,w,middle):
            right = middle 
        else:
            left = middle + 1
     left < right left right middle = (left + right) // 2 middle (left + right) // 2 left + right left right 2 if hantei(t,w,middle):
            right = middle 
        else:
            left = middle + 1
     hantei(t,w,middle) hantei t w middle right = middle right middle left = middle + 1 left middle + 1 middle 1 return left left t t w w def hantei(t,w,p):
    track_on = 0
    daisu = 1
    for j in range(len(w)):     
        track_on += w[j]
        if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
    return True hantei track_on = 0 track_on 0 daisu = 1 daisu 1 for j in range(len(w)):     
        track_on += w[j]
        if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
     j range(len(w)) range len(w) len w track_on += w[j] track_on w[j] w j if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
     track_on > p track_on p daisu += 1 daisu 1 track_on = w[j] track_on w[j] w j if daisu > t:
                return False
     daisu > t daisu t return False False return True True t t w w p p nimotsu, track = map(int,input().split()) nimotsu map(int,input().split()) map int input().split() ().split () input split track weight = list(map(int,sys.stdin.readlines())) weight list(map(int,sys.stdin.readlines())) list map(int,sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines print(binarySearch(track,weight)) print binarySearch(track,weight) binarySearch track weight def binarySearch(t,w):
    left = max(w)
    right = sum(w)
    while left < right:
        middle = (left + right) // 2
        if hantei(t,w,middle):
            right = middle 
        else:
            left = middle + 1
    return left
             def binarySearch(t,w):
    left = max(w)
    right = sum(w)
    while left < right:
        middle = (left + right) // 2
        if hantei(t,w,middle):
            right = middle 
        else:
            left = middle + 1
    return left
             binarySearch weight = list(map(int,sys.stdin.readlines())) list(map(int,sys.stdin.readlines())) weight def hantei(t,w,p):
    track_on = 0
    daisu = 1
    for j in range(len(w)):     
        track_on += w[j]
        if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
    return True def hantei(t,w,p):
    track_on = 0
    daisu = 1
    for j in range(len(w)):     
        track_on += w[j]
        if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
    return True hantei track = map(int,input().split()) map(int,input().split()) track nimotsu, track = map(int,input().split()) map(int,input().split()) nimotsu
import sys

def binarySearch(t,w):
    left = max(w)
    right = sum(w)
    while left < right:
        middle = (left + right) // 2
        if hantei(t,w,middle):
            right = middle 
        else:
            left = middle + 1
    return left
            
def hantei(t,w,p):
    track_on = 0
    daisu = 1
    for j in range(len(w)):     
        track_on += w[j]
        if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
    return True


nimotsu, track = map(int,input().split())
weight = list(map(int,sys.stdin.readlines()))



print(binarySearch(track,weight))