#!/usr/bin/env python3
from heapq import *
n,k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
heap,tasks = arr[:k], arr[:k-1:-1]
heapify(heap)
best = 0
time = 0
while heap:
    newtime = heappop(heap)
    best = max(newtime-time,best)
    time = newtime
    if tasks: heappush(heap,time+tasks.pop())
print(best)
