#!/usr/bin/python3
from heapq import heappush, heappop

n, k = [int(x) for x in input().split()]
ds = [int(x) for x in input().split()]

biggest_gap = 0
cur_time = 0
servers = [0]*k
for d in ds:
    new_time = heappop(servers)
    biggest_gap = max(biggest_gap, new_time - cur_time)
    cur_time = new_time
    heappush(servers, cur_time + d)

while len(servers) > 0:
    new_time = heappop(servers)
    biggest_gap = max(biggest_gap, new_time - cur_time)
    cur_time = new_time

print(biggest_gap)
