#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define int long long
inline void solve()
{
	int n,k;
	cin>>n>>k;
	pair<int,int> a[n];
	int b[n];
	for (int i=0;i<n;i++)
	{
		cin>>a[i].first;
		a[i].second=i;
		b[i]=a[i].first;
	}
	sort(a,a+n);
	reverse(a,a+n);
	int ans=0;
	set<int>s;
	for (int i=0;i<n;i++)
		s.insert(i);
	for (int i=0;i+1<k;i++)
	{
		ans+=a[i].first;
		s.erase(a[i].second);
	}
	int z=0,j=0;
	for (auto i:s)
	{
		z=max(z,b[i]+j);
		j++;
	}
	ans+=z;
	ans+=k;
	cout<<ans<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);cout.tie(NULL);
	int t=1;
	// cin>>t;
	while (t--)
		solve();
}