import sys
def slove(goods, carnum, P):
    tot_good = len(goods)
    cur_good = 0
    for _ in range(carnum):
        load = 0
        while cur_good < tot_good and goods[cur_good] <= P -load:
            load += goods[cur_good]
            cur_good += 1
    if cur_good == tot_good:
        return True
    else:
        return False

if __name__ == '__main__':

    datas = input().split(' ')
    good_num = int(datas[0])
    car_num = int(datas[1])
    goods = []
    for _ in range(good_num):
        goods.append(int(input()))

    left = 0
    right = sys.maxsize
    while left < right:
        mid = (left + right) // 2
        if slove(goods, car_num, mid):
            # 当前的P较大
            right = mid
        else:
            left = mid + 1
    print(right)
     import sys sys def slove(goods, carnum, P):
    tot_good = len(goods)
    cur_good = 0
    for _ in range(carnum):
        load = 0
        while cur_good < tot_good and goods[cur_good] <= P -load:
            load += goods[cur_good]
            cur_good += 1
    if cur_good == tot_good:
        return True
    else:
        return False slove tot_good = len(goods) tot_good len(goods) len goods cur_good = 0 cur_good 0 for _ in range(carnum):
        load = 0
        while cur_good < tot_good and goods[cur_good] <= P -load:
            load += goods[cur_good]
            cur_good += 1
     _ range(carnum) range carnum load = 0 load 0 while cur_good < tot_good and goods[cur_good] <= P -load:
            load += goods[cur_good]
            cur_good += 1
     cur_good < tot_good and goods[cur_good] <= P -load cur_good < tot_good cur_good tot_good goods[cur_good] <= P -load goods[cur_good] goods cur_good P -load P load load += goods[cur_good] load goods[cur_good] goods cur_good cur_good += 1 cur_good 1 if cur_good == tot_good:
        return True
    else:
        return False cur_good == tot_good cur_good tot_good return True True return False False goods goods carnum carnum P P if __name__ == '__main__':

    datas = input().split(' ')
    good_num = int(datas[0])
    car_num = int(datas[1])
    goods = []
    for _ in range(good_num):
        goods.append(int(input()))

    left = 0
    right = sys.maxsize
    while left < right:
        mid = (left + right) // 2
        if slove(goods, car_num, mid):
            # 当前的P较大
            right = mid
        else:
            left = mid + 1
    print(right)
     __name__ == '__main__' __name__ '__main__' datas = input().split(' ') datas input().split(' ') ().split () input split ' ' good_num = int(datas[0]) good_num int(datas[0]) int datas[0] datas 0 car_num = int(datas[1]) car_num int(datas[1]) int datas[1] datas 1 goods = [] goods [] for _ in range(good_num):
        goods.append(int(input()))

     _ range(good_num) range good_num goods.append(int(input())) goods.append goods append int(input()) int input() input left = 0 left 0 right = sys.maxsize right sys.maxsize sys maxsize while left < right:
        mid = (left + right) // 2
        if slove(goods, car_num, mid):
            # 当前的P较大
            right = mid
        else:
            left = mid + 1
     left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if slove(goods, car_num, mid):
            # 当前的P较大
            right = mid
        else:
            left = mid + 1
     slove(goods, car_num, mid) slove goods car_num mid right = mid right mid left = mid + 1 left mid + 1 mid 1 print(right) print right good_num = int(datas[0]) int(datas[0]) good_num goods = [] [] goods def slove(goods, carnum, P):
    tot_good = len(goods)
    cur_good = 0
    for _ in range(carnum):
        load = 0
        while cur_good < tot_good and goods[cur_good] <= P -load:
            load += goods[cur_good]
            cur_good += 1
    if cur_good == tot_good:
        return True
    else:
        return False def slove(goods, carnum, P):
    tot_good = len(goods)
    cur_good = 0
    for _ in range(carnum):
        load = 0
        while cur_good < tot_good and goods[cur_good] <= P -load:
            load += goods[cur_good]
            cur_good += 1
    if cur_good == tot_good:
        return True
    else:
        return False slove right = mid mid right datas = input().split(' ') input().split(' ') datas left = 0 0 left right = sys.maxsize sys.maxsize right mid = (left + right) // 2 (left + right) // 2 mid left = mid + 1 mid + 1 left car_num = int(datas[1]) int(datas[1]) car_num
import sys
def slove(goods, carnum, P):
    tot_good = len(goods)
    cur_good = 0
    for _ in range(carnum):
        load = 0
        while cur_good < tot_good and goods[cur_good] <= P -load:
            load += goods[cur_good]
            cur_good += 1
    if cur_good == tot_good:
        return True
    else:
        return False

if __name__ == '__main__':

    datas = input().split(' ')
    good_num = int(datas[0])
    car_num = int(datas[1])
    goods = []
    for _ in range(good_num):
        goods.append(int(input()))

    left = 0
    right = sys.maxsize
    while left < right:
        mid = (left + right) // 2
        if slove(goods, car_num, mid):
            # 当前的P较大
            right = mid
        else:
            left = mid + 1
    print(right)
    
