import bisect
n,k=map(int,input().split())
A=list(map(int,input().split()))
z=0
a=A[:k-1]
s=sum(a)
a.sort(reverse=True)
for i in range(k-1,n):
    z=max(z,s+A[i]+i+1)
    if k!=1 and a[-1]<A[i]:
        s-=a[-1]
        a.pop(-1)
        l=bisect.bisect_left(a,A[i])
        a=a[:l]+[A[i]]+a[l:]
        s+=A[i]
print(z)
