n,k=map(int,input().split())
A=list(map(int,input().split()))
z=0
a=A[:k-1]
s=sum(a)
a.sort()
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[0]
        a[0]=A[i]
        s+=A[i]
        a.sort()
print(z)
