#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector<pair<ll int,ll int> >p;
bool compare(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
{
    if(p1.first==p2.second)
    return p1.first<p2.first;
    else
     return p1.second<p2.second;

}
int main()
{
ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
ll int prev =0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]<0)
    {count++;
    prev = i;
    }
}

if(count>k)
{
    cout<<-1;
    return 0;
}

if(count==0)
{cout<<0;
return 0;
}

ll int r=0;
ll int m=0;
ll int ans=0;
for(int i=0;i<n;i++)
{
    if(arr[i]<0)
    {
        ans++;

        while(i<n && arr[i]<0)
        {
            i++;
        }
        if(i<n)
        {
            ans++;
            r=0;
            m = i;

            while(arr[i]>=0 && i<n)
            {
                i++;
                r++;
            }
            i--;
            if(r>0)
           p.push_back(make_pair(m,r));

        }

    }
}
//cout<<ans;
 k  = k -count;
// cout<<k<<" "<<ans<<"\n";
sort(p.begin(),p.end(),compare);
 m  = p.size();
 /*for(int i=0;i<m;i++)
 {
     cout<<p[i].first<<" "<<p[i].second<<" "<<prev<<"\n";
 }*/
 for(int i=0;i<m;i++)
 {

     if(k==0)
     break;
     if(p[i].second<=k)
     {
         if(p[i].first<prev)
         {

         k = k - p[i].second;
           ans-=2;        // cout<<k<<" ";
         }
         else
         {  ans-=1;
           k  =  k - p[i].second;
         }
     }
     else
     {
         break;
     }
    // cout<<k<<"\n";
 }
 cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector<pair<ll int,ll int> >p;
bool compare(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
{
    if(p1.second==p2.second)
    return p1.first<p2.first;
    return p1.second<p2.second;

}
int main()
{
ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
ll int prev =0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]<0)
    {count++;
    prev = i;
    }
}

if(count>k)
{
    cout<<-1;
    return 0;
}
if(count==0)
{cout<<0;
return 0;
}

ll int r=0;
ll int m=0;
ll int ans=0;
for(int i=0;i<n;i++)
{
    if(arr[i]<0)
    {
        ans+=2;

        while(i<n && arr[i]<0)
        {
            i++;
        }
        if(i<n)
        {
            r=0;
            m = i;

            while(arr[i]>=0 && i<n)
            {
                i++;
                r++;
            }
            i--;
           p.push_back(make_pair(m,r));

        }

    }
}
//cout<<k<<" "<<count<<"\n";
 k  = k -count;
// cout<<k<<" "<<ans<<"\n";
sort(p.begin(),p.end(),compare);
 m  = p.size();
 /*for(int i=0;i<m;i++)
 {
     cout<<p[i].first<<" "<<p[i].second<<"\n";
 }*/
 for(int i=0;i<m;i++)
 {
     if(p[i].second<=k)
     {
         if(p[i].first<prev)
         {

         k = k - p[i].second;
           ans-=2;        // cout<<k<<" ";
         }
         else
         ans--;
     }
     else
     {
         break;
     }
 }
 cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector<pair<ll int,ll int> >p;
bool compare(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
{
    if(p1.second==p2.second)
    return p1.first<p2.first;
    return p1.second<p2.second;

}
int main()
{
ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
ll int prev =0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]<0)
    {count++;
    prev = i;
    }
}

if(count>k)
{
    cout<<-1;
    return 0;
}

if(count==0)
{cout<<0;
return 0;
}

ll int r=0;
ll int m=0;
ll int ans=0;
for(int i=0;i<n;i++)
{
    if(arr[i]<0)
    {
        ans++;

        while(i<n && arr[i]<0)
        {
            i++;
        }
        if(i<n)
        {
            ans++;
            r=0;
            m = i;

            while(arr[i]>=0 && i<n)
            {
                i++;
                r++;
            }
            i--;
           p.push_back(make_pair(m,r));

        }

    }
}
//cout<<ans;
 k  = k -count;
// cout<<k<<" "<<ans<<"\n";
sort(p.begin(),p.end(),compare);
 m  = p.size();
 /*for(int i=0;i<m;i++)
 {
     cout<<p[i].first<<" "<<p[i].second<<"\n";
 }*/
 for(int i=0;i<m;i++)
 {
     if(p[i].second<=k)
     {
         if(p[i].first<prev)
         {

         k = k - p[i].second;
           ans-=2;        // cout<<k<<" ";
         }
         else
         ans--;
     }
     else
     {
         break;
     }
 }
 cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007

int main()
{

ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];

    if(arr[i]<0)
    {
        count++;
    }
}
if(count>k)
{
    cout<<"-1";
    return 0;
}
ll int pos[count];
ll int count1;
ll int m=0;
ll int prev=-1;
for(int i=0;i<n;i++)
{

    if(arr[i]<0 && prev!=-1)
    { pos[m] = i-prev;
      m++;

    }
    if(arr[i]<0)
    {
        prev  = i;
    }
}

ll int ans=0;
ll int curr=0;

ll int flag=1;

for(int i=0;i<prev;i++)
{
    if(arr[i]>0)
    continue;
    else
    {  if(flag==1)
        {

            ans+=1;

          flag=0;
           k =k-1;

        }

       // cout<<curr<<"\n";
         if(pos[curr] +  count-curr-2 <=k)
        {
           // cout<<ans<<"ffff"<<"\n";
             k = k - pos[curr];

             i+=pos[curr]-1;
             curr++;
             //cout<<i<<"\n";
             //cout<<k<<"\n";
        }
        else
        {
            ans+=1;
            flag=1;
            curr++;
           // cout<<"fff";

        }
       // cout<<ans<<"\n";
    }
}

if(flag==1)
{ans+=1;
k = k-1;
}
if(k>=n-1-prev)
cout<<ans<<"\n";
else
cout<<ans+1<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector<pair<ll int,ll int> >p;
bool compare(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
{
    if(p1.second==p2.second)
    return p1.first<p2.first;
    return p1.second<p2.second;

}
int main()
{
ll int n,k;
cin>>n>>k;
ll int arr[n];
ll int count=0;
ll int prev =0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]<0)
    {count++;
    prev = i;
    }
}

if(count>k)
{
    cout<<-1;
    return 0;
}

if(count==0)
{cout<<0;
return 0;
}

ll int r=0;
ll int m=0;
ll int ans=0;
for(int i=0;i<n;i++)
{
    if(arr[i]<0)
    {
        ans++;

        while(i<n && arr[i]<0)
        {
            i++;
        }
        if(i<n)
        {
            ans++;
            r=0;
            m = i;

            while(arr[i]>=0 && i<n)
            {
                i++;
                r++;
            }
            i--;
            if(r>0)
           p.push_back(make_pair(m,r));

        }

    }
}
//cout<<ans;
 k  = k -count;
// cout<<k<<" "<<ans<<"\n";
sort(p.begin(),p.end(),compare);
 m  = p.size();
 /*for(int i=0;i<m;i++)
 {
     cout<<p[i].first<<" "<<p[i].second<<" "<<prev<<"\n";
 }*/
 for(int i=0;i<m;i++)
 {

     if(k==0)
     break;
     if(p[i].second<=k)
     {
         if(p[i].first<prev)
         {

         k = k - p[i].second;
           ans-=2;        // cout<<k<<" ";
         }
         else
         {  ans-=1;
           k  =  k - p[i].second;
         }
     }
     else
     {
         break;
     }
    // cout<<k<<"\n";
 }
 cout<<ans<<"\n";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define FOP freopen("data.txt","r",stdin)
#define FOP2 freopen("data1.txt","w",stdout)
#define inf_LL 4223372036854775807
#define inf 0x3f3f3f3f
#define maxn 200010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

struct Node
{
    int pos, len;
    Node(int p = 0, int l = 0) : pos(p), len(l) {}
};

bool cmp(Node a, Node b)
{
    return a.len < b.len;
}

int n, k;
int a[maxn];
vector<Node> vec;
vector<Node> vec2;

int main()
{
    while(~scanf("%d%d", &n, &k))
    {
        vec.resize(0);
        vec2.resize(0);
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        for(int i = 1; i <= n; i++)
        {
            if(a[i] < 0)
            {
                Node node = Node(i, 0);
                while(i <= n && a[i] < 0) i++, node.len++;
                vec.push_back(node);
            }
        }

        int ans = 0;
        for(int i = 0; i < vec.size(); i++)
        {
            //printf("%d %d\n", vec[i].pos, vec[i].len);
            ans += 2;
            if(vec[i].pos + vec[i].len > n) ans--;
            k -= vec[i].len;
            //printf("%d\n", k);
        }
        if(k < 0) printf("-1\n");
        else if(vec.size() == 0) printf("0\n");
        else
        {

            //printf("%d %d\n", k, ans);

            int len;
            for(int i = 1; i < vec.size(); i++)
            {
                len = vec[i].pos - (vec[i-1].pos + vec[i-1].len - 1) - 1;
                //printf("%d %d\n", i-1, len);
                vec2.push_back(Node(i-1, len));
            }

            sort(vec2.begin(), vec2.end(), cmp);
            for(int i = 0; i < vec2.size(); i++)
            {
                if(k >= vec2[i].len)
                {
                    k -= vec2[i].len;
                    //if(vec2[i].pos == vec.size()-1) ans--;
                    //else
                    ans -= 2;
                }
            }

            len = n - (vec.back().pos + vec.back().len - 1);
            if(k >= len) ans--;
            printf("%d\n", ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define FOP freopen("data.txt","r",stdin)
#define FOP2 freopen("data1.txt","w",stdout)
#define inf_LL 4223372036854775807
#define inf 0x3f3f3f3f
#define maxn 200010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

struct Node
{
    int pos, len;
    Node(int p = 0, int l = 0) : pos(p), len(l) {}
};

bool cmp(Node a, Node b)
{
    return a.len < b.len;
}

int n, k;
int a[maxn];
vector<Node> vec;
vector<Node> vec2;

int main()
{
    while(~scanf("%d%d", &n, &k))
    {
        vec.resize(0);
        vec2.resize(0);
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        for(int i = 1; i <= n; i++)
        {
            if(a[i] < 0)
            {
                Node node = Node(i, 0);
                while(i <= n && a[i] < 0) i++, node.len++;
                vec.push_back(node);
            }
        }

        int ans = 0;
        for(int i = 0; i < vec.size(); i++)
        {
            //printf("%d %d\n", vec[i].pos, vec[i].len);
            ans += 2;
            if(vec[i].pos + vec[i].len > n) ans--;
            k -= vec[i].len;
            //printf("%d\n", k);
        }
        if(k < 0) printf("-1\n");
        else if(vec.size() == 0) printf("0\n");
        else
        {

            //printf("%d %d\n", k, ans);

            int len;
            for(int i = 1; i < vec.size(); i++)
            {
                len = vec[i].pos - (vec[i-1].pos + vec[i-1].len - 1) - 1;
                //printf("%d %d\n", i-1, len);
                vec2.push_back(Node(i-1, len));
            }
            len = n - (vec.back().pos + vec.back().len - 1);
            if(len > 0) vec2.push_back(Node(vec.size()-1, len));

            sort(vec2.begin(), vec2.end(), cmp);
            for(int i = 0; i < vec2.size(); i++)
            {
                if(k >= vec2[i].len)
                {
                    k -= vec2[i].len;
                    if(vec2[i].pos == vec.size()-1) ans--;
                    else ans -= 2;
                }
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define FOP freopen("data.txt","r",stdin)
#define FOP2 freopen("data1.txt","w",stdout)
#define inf_LL 4223372036854775807
#define inf 0x3f3f3f3f
#define maxn 200010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

int n, k;
int a[maxn];

int main()
{
    while(~scanf("%d%d", &n, &k))
    {
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        int pi = 1, ans = 0;
        while(pi <= n && a[pi] >= 0) pi++;
        while(pi <= n)
        {
            ans++;
            int i = pi+k-1;
            if(i >= n) break;

            //printf("%d\n", a[i]);

            if(a[i] >= 0)
            {
                ans++;
                while(i <= n && a[i] >= 0) i++;
                if(i > n) break;
                pi = i;
            }
            else
            {
                if(a[i+1] >= 0) { pi = i+1; continue; }
                ans++;
                while(i >= pi && a[i] < 0) i--;
                if(i < pi) { ans = -1; break; }
                pi = i+1;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define FOP freopen("data.txt","r",stdin)
#define FOP2 freopen("data1.txt","w",stdout)
#define inf_LL 4223372036854775807
#define inf 0x3f3f3f3f
#define maxn 200010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

int n, k;
int a[maxn];

int main()
{
    while(~scanf("%d%d", &n, &k))
    {
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        int pi = 1, ans = 0;
        while(pi <= n && a[pi] >= 0) pi++;
        while(pi <= n)
        {
            ans++;
            int i = pi+k-1;
            if(i > n) break;

            //printf("%d\n", a[i]);

            if(a[i] >= 0)
            {
                ans++;
                while(i <= n && a[i] >= 0) i++;
                if(i > n) break;
                pi = i;
            }
            else
            {
                if(a[i+1] >= 0) { pi = i+1; continue; }
                ans++;
                while(i >= pi && a[i] < 0) i--;
                if(i < pi) { ans = -1; break; }
                pi = i+1;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define FOP freopen("data.txt","r",stdin)
#define FOP2 freopen("data1.txt","w",stdout)
#define inf_LL 4223372036854775807
#define inf 0x3f3f3f3f
#define maxn 200010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

struct Node
{
    int pos, len;
    Node(int p = 0, int l = 0) : pos(p), len(l) {}
};

bool cmp(Node a, Node b)
{
    return a.len < b.len;
}

int n, k;
int a[maxn];
vector<Node> vec;
vector<Node> vec2;

int main()
{
    while(~scanf("%d%d", &n, &k))
    {
        vec.resize(0);
        vec2.resize(0);
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        for(int i = 1; i <= n; i++)
        {
            if(a[i] < 0)
            {
                Node node = Node(i, 0);
                while(i <= n && a[i] < 0) i++, node.len++;
                vec.push_back(node);
            }
        }

        int ans = 0;
        for(int i = 0; i < vec.size(); i++)
        {
            //printf("%d %d\n", vec[i].pos, vec[i].len);
            ans += 2;
            if(vec[i].pos + vec[i].len > n) ans--;
            k -= vec[i].len;
            //printf("%d\n", k);
        }
        if(k < 0) printf("-1\n");
        else if(vec.size() == 0) printf("0\n");
        else
        {

            //printf("%d %d\n", k, ans);

            int len;
            for(int i = 1; i < vec.size(); i++)
            {
                len = vec[i].pos - (vec[i-1].pos + vec[i-1].len - 1) - 1;
                //printf("%d %d\n", i-1, len);
                vec2.push_back(Node(i-1, len));
            }

            sort(vec2.begin(), vec2.end(), cmp);
            for(int i = 0; i < vec2.size(); i++)
            {
                if(k >= vec2[i].len)
                {
                    k -= vec2[i].len;
                    //if(vec2[i].pos == vec.size()-1) ans--;
                    //else
                    ans -= 2;
                }
            }

            len = n - (vec.back().pos + vec.back().len - 1);
            if(len > 0 && k >= len) ans--;
            printf("%d\n", ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(a,0);mset(b,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){ b[index]++; flag=1;}
			else if (a[i]<0){
				sum++;
				if (flag) { index++; flag=0;}
			}
		}
		if (sum>k){ printf ("-1\n"); continue; }
		if(a[n-1]<0) index--;
		int temp=INF;
		if (a[n-1]>=0) temp=b[index],b[index]=INF;
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		if (a[0]<0) res++;
		else b[0]=INF;
		sort(b,b+index+1);
		k-=sum;
		for (int i=0;i<=index;i++){
			if (k>=b[i]){
				k-=b[i];
				res-=2;
			}
			else if (k>=temp&&res){
				res--;break;
			}
		}
		printf ("%d\n",res);
	}
	return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(a,0);mset(b,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){
				b[index]++; flag=1;
			}
			else if (a[i]<0){
				sum++;
				if (flag){
					index++; flag=0;
				}
			}
		}
		if(a[n-1]<0) index--;
		if (sum>k){
			printf ("-1\n"); continue;
		}
		if (sum==n&&sum<=k){
			printf ("1\n"); continue;
		}
		int temp=INF;
		if (a[n-1]>=0) temp=b[index],b[index]=INF;
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		if (a[0]<0) res++;
		else b[0]=INF;
		sort(b,b+index+1);
		k-=sum;
		for (int i=0;i<=index;i++){
			if (k>=b[i]){
				k-=b[i];
				res-=2;
			}
			else if (k>=temp){
				res--;break;
			}
		}
		printf ("%d\n",res);
	}
	return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(a,0);mset(b,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){
				b[index]++;
				flag=1;
			}
			else if (a[i]<0){
				sum++;
				if (flag){
					index++;
					flag=0;
				}
			}
		}
		if (sum>k){
			printf ("-1\n"); continue;
		}
		if (sum==n&&sum<=k){
			printf ("1\n"); continue;
		}
		int temp=-1;
		if (a[n-1]>=0) temp=b[index];
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		if (a[0]<0) res++;
		else b[0]=INF;
		sort(b,b+index+1);
		k-=sum;
		for (int i=0;i<=index;i++){
			if (k>=b[i]){
				k-=b[i];
				if ((b[i]==temp&&i==index)||(b[i]==temp&&b[i+1]>temp)) res--;
				else res-=2;
			}
		}
		printf ("%d\n",res);
	}
	return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(a,0);mset(b,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){
				b[index]++; flag=1;
			}
			else if (a[i]<0){
				sum++;
				if (flag){
					index++; flag=0;
				}
			}
		}
		if(a[n-1]<0) index--;
		if (sum>k){
			printf ("-1\n"); continue;
		}
		if (sum==n&&sum<=k){
			printf ("1\n"); continue;
		}
		int temp=-1;
		if (a[n-1]>=0) temp=b[index];
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		if (a[0]<0) res++;
		else b[0]=INF;
		sort(b,b+index+1);
		k-=sum;
		for (int i=0;i<=index;i++){
			if (k>=b[i]){
				k-=b[i];
				if ((b[i]==temp&&i==index)||(b[i]==temp&&b[i+1]>temp)) res--;
				else res-=2;
			}
		}
		printf ("%d\n",res);
	}
	return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(b,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){
				b[index]++;
				flag=1;
			}
			else if (a[i]<0) {
				sum++;
				if (flag){
					index++;
					flag=0;
				}
			}
		}
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		int temp,temp2;
		if (a[0]<0) res++;
		else b[0]=INF;
		if (a[n-1]>=0) temp=b[index];
		if (sum>k){
			printf ("-1\n");
			continue;
		}
		sort(b,b+index+1);
		k-=sum;
		int tot=0;
		int flag2=0;
		for (int i=0;i<=index;i++){
			tot+=b[i];
			if (tot<=k) {
				if ((b[i]==temp&&b[i+1]>temp)||(b[i]==temp&&i+1==index+1)) flag2=1;
				res-=2;
			}
			else break;
		}
		if (flag2) res++;
		printf ("%d\n",res);
	}
	return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(a,0);mset(b,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){
				b[index]++; flag=1;
			}
			else if (a[i]<0){
				sum++;
				if (flag){
					index++; flag=0;
				}
			}
		}
		if(a[n-1]<0) index--;
		if (sum>k){
			printf ("-1\n"); continue;
		}
		if (sum==n&&sum<=k){
			printf ("1\n"); continue;
		}
		int temp=INF;
		if (a[n-1]>=0) temp=b[index],b[index]=INF;
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		if (a[0]<0) res++;
		else b[0]=INF;
		sort(b,b+index+1);
		k-=sum;
		for (int i=0;i<=index;i++){
			if (k>=b[i]){
				k-=b[i];
				res-=2;
			}
			else if (k>=temp&&res){
				res--;break;
			}
		}
		printf ("%d\n",res);
	}
	return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(b,0);mset(a,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){
				b[index]++;
				flag=1;
			}
			else if (a[i]<0) {
				sum++;
				if (flag){
					index++;
					flag=0;
				}
			}
		}
		if (sum==n&&sum<=k){
			printf ("1\n");
			continue;
		}
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		int temp,temp2;
		if (a[0]<0) res++;
		else b[0]=INF;
		if (a[n-1]>=0) temp=b[index];
		if (sum>k){
			printf ("-1\n");
			continue;
		}
		sort(b,b+index+1);
		k-=sum;
		int tot=0;
		int flag2=0;
		for (int i=0;i<=index;i++){
			tot+=b[i];
			if (tot<=k) {
				if ((b[i]==temp&&b[i+1]>temp)||(b[i]==temp&&i+1==index+1)) flag2=1;
				res-=2;
			}
			else break;
		}
		if (flag2) res++;
		printf ("%d\n",res);
	}
	return 0;
}


#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const int MAX=1e5+10;
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
int a[200005];
int b[200005];
int main (){
	int n,k;
	while (scanf ("%d%d",&n,&k)!=EOF){
		int sum=0;
		int index=0;
		mset(a,0);mset(b,0);
		int flag=0;
		for (int i=0;i<n;i++){
			scanf ("%d",&a[i]);
			if (a[i]>=0){
				b[index]++;
				flag=1;
			}
			else if (a[i]<0) {
				sum++;
				if (flag){
					index++;
					flag=0;
				}
			}
		}
		if (sum>k){
			printf ("-1\n"); continue;
		}
		if (sum==n&&sum<=k){
			printf ("1\n"); continue;
		}
		int temp=-1;
		if (a[n-1]>=0) temp=b[index];
		int res=0;
		for (int i=1;i<n;i++){
			if ((a[i]*a[i-1]<0)||(a[i-1]<0&&a[i]==0)||(a[i-1]==0&&a[i]<0)) res++;
		}
		if (a[0]<0) res++;
		else b[0]=INF;
		sort(b,b+index);
		k-=sum;
		for (int i=0;i<=index;i++){
			if (k>=b[i]){
				k-=b[i];
				if ((b[i]==temp&&i+1>index)||(b[i]==temp&&b[i+1]>temp)) res--;
				else res-=2;
			}
		}
		printf ("%d\n",res);
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long int n,k,c=0,i,id,id1,j,l=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
            {c=c+2;
            l++;
            id=i+1;
            }

    }
    if(k<l)
        cout<<-1;
        else if(l==0)
            cout<<0;
        else if(l==1)
        {k--;
            if((k-(n-id))>=0)
                cout<<1;
            else
                cout<<2;
        }
    else
    {

    vector<long int>v;
    for(i=0;i<n;i++)
    {

        if(a[i]<0)
        {
            id1=i;
            break;
        }

    }
    for(i=id1+1,j=0;i<n;i++)
    {
        if(a[i]<0)
        {
            v.push_back(i-id1-1);
           //v[j]=i-id1-1;
            j++;
            id1=i;
        }
    }
    sort(v.begin(),v.end());
    //for(i=0;i<j;i++)
        //cout<<v[i];
    k=k-l;
    i=0;
    while(k-v[i]>=0&&i<j)
    {k=k-v[i];
        c=c-2;
        i++;
    }
   // cout<<k;
    if((k-(n-id))>=0)
        c--;
    cout<<c;
    }
    return 0;

}


#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long int n,k,c=0,i,id,id1,j,l=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
            {c=c+2;
            l++;
            id=i+1;
            }

    }
    vector<long int>v;
    for(i=0;i<n;i++)
    {

        if(a[i]<0)
        {
            id1=i;
            break;
        }

    }
    for(i=id1+1,j=0;i<n;i++)
    {
        if(a[i]<0)
        {
            v.push_back(i-id1-1);
           //v[j]=i-id1-1;
            j++;
            id1=i;
        }
    }
    sort(v.begin(),v.end());
    //for(i=0;i<j;i++)
        //cout<<v[i];
    k=k-l;
    i=0;
    while(k-v[i]>=0&&i<j)
    {k=k-v[i];
        c=c-2;
        i++;
    }
   // cout<<k;
    if((k-(n-id))>=0)
        c--;
    cout<<c;
    return 0;

}


#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long int n,k,c=0,i,id,id1,j,l=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
            {c=c+2;
            l++;
            id=i+1;
            }

    }
    if(k<l)
        cout<<-1;
        else if(l==0)
            cout<<0;
        else if(l==1)
        {k--;
            if((k-(n-id))>=0)
                cout<<1;
            else
                cout<<0;
        }
    else
    {

    vector<long int>v;
    for(i=0;i<n;i++)
    {

        if(a[i]<0)
        {
            id1=i;
            break;
        }

    }
    for(i=id1+1,j=0;i<n;i++)
    {
        if(a[i]<0)
        {
            v.push_back(i-id1-1);
           //v[j]=i-id1-1;
            j++;
            id1=i;
        }
    }
    sort(v.begin(),v.end());
    //for(i=0;i<j;i++)
        //cout<<v[i];
    k=k-l;
    i=0;
    while(k-v[i]>=0&&i<j)
    {k=k-v[i];
        c=c-2;
        i++;
    }
   // cout<<k;
    if((k-(n-id))>=0)
        c--;
    cout<<c;
    }
    return 0;

}


#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long int n,k,c=0,i,id,id1,j,l=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
            {c=c+2;
            l++;
            id=i+1;
            }

    }
    if(k<l)
        cout<<-1;
    else
    {

    vector<long int>v;
    for(i=0;i<n;i++)
    {

        if(a[i]<0)
        {
            id1=i;
            break;
        }

    }
    for(i=id1+1,j=0;i<n;i++)
    {
        if(a[i]<0)
        {
            v.push_back(i-id1-1);
           //v[j]=i-id1-1;
            j++;
            id1=i;
        }
    }
    sort(v.begin(),v.end());
    //for(i=0;i<j;i++)
        //cout<<v[i];
    k=k-l;
    i=0;
    while(k-v[i]>=0&&i<j)
    {k=k-v[i];
        c=c-2;
        i++;
    }
   // cout<<k;
    if((k-(n-id))>=0)
        c--;
    cout<<c;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[200005]={};
int main()
{
    int a,b;
    while(cin>>a>>b){
        vector<int>num;
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<a;i++){
            if(A[i]<0)
                num.push_back(i);
        }
        if(num.sz>b){
            cout<<-1<<endl;
            con;
        }
        vector<int>now;
        for(int i=0;i<num.sz-1;i++){
            now.push_back(num[i+1]-num[i]);
        }
        sort(now.begin(),now.end());
        int ans=0,flag=0;
        for(int i=0;i<a;i++){
            if(A[i]<0&&!flag){
                ans++;
                flag=1;
            }
            else if(A[i]>=0&&flag){
                flag=0;
                ans++;
            }
        }
        int k=b-num.sz;
        for(int i=0;i<now.sz;i++){
            int tmp=(now[i]-1);
            if(tmp==0)
                con;
            if(tmp<=k){
                k-=tmp;
                ans-=2;
            }
        }
        int l=now.back();
        int r=a-1;
        if(r-l<=k&&r-l!=0){
            ans--;
        }
        cout<<ans<<endl;
    }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[200005]={};
int main()
{
    int a,b;
    while(cin>>a>>b){
        vector<int>num;
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<a;i++){
            if(A[i]<0)
                num.push_back(i);
        }
        if(num.sz>b){
            cout<<-1<<endl;
            con;
        }
        if(num.sz==0){
            cout<<1<<endl;
            con;
        }
        vector<int>now;
        for(int i=0;i<num.sz-1;i++){
            now.push_back(num[i+1]-num[i]);
        }
        sort(now.begin(),now.end());
        int ans=0,flag=0;
        for(int i=0;i<a;i++){
            if(A[i]<0&&!flag){
                ans++;
                flag=1;
            }
            else if(A[i]>=0&&flag){
                flag=0;
                ans++;
            }
        }
        int k=b-num.sz;
        for(int i=0;i<now.sz;i++){
            int tmp=(now[i]-1);
            if(tmp==0)
                con;
            if(tmp<=k){
                k-=tmp;
                ans-=2;
            }
        }
        int l=0;
        for(int i=0;i<a;i++)
            if(A[i]<0)
                l=i;
        int r=a-1;
        if(r-l<=k&&r-l!=0){
            ans--;
        }
        cout<<ans<<endl;
    }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[200005]={};
int main()
{
    int a,b;
    while(cin>>a>>b){
        vector<int>num;
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<a;i++){
            if(A[i]<0)
                num.push_back(i);
        }
        if(num.sz>b){
            cout<<-1<<endl;
            con;
        }
        if(num.sz==0){
            cout<<0<<endl;
            con;
        }
        vector<int>now;
        for(int i=0;i<num.sz-1;i++){
            now.push_back(num[i+1]-num[i]);
        }
        sort(now.begin(),now.end());
        int ans=0,flag=0;
        for(int i=0;i<a;i++){
            if(A[i]<0&&!flag){
                ans++;
                flag=1;
            }
            else if(A[i]>=0&&flag){
                flag=0;
                ans++;
            }
        }
        int k=b-num.sz;
        for(int i=0;i<now.sz;i++){
            int tmp=(now[i]-1);
            if(tmp==0)
                con;
            if(tmp<=k){
                k-=tmp;
                ans-=2;
            }
        }
        int l=0;
        for(int i=0;i<a;i++)
            if(A[i]<0)
                l=i;
        int r=a-1;
        if(r-l<=k&&r-l!=0){
            ans--;
        }
        cout<<ans<<endl;
    }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[200005]={};
int main()
{
    int a,b;
    while(cin>>a>>b){
        vector<int>num;
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<a;i++){
            if(A[i]<0)
                num.push_back(i);
        }
        if(num.sz>b){
            cout<<-1<<endl;
            con;
        }
        vector<int>now;
        for(int i=0;i<num.sz-1;i++){
            now.push_back(num[i+1]-num[i]);
        }
        sort(now.begin(),now.end());
        int ans=0,flag=0;
        for(int i=0;i<a;i++){
            if(A[i]<0&&!flag){
                ans++;
                flag=1;
            }
            else if(A[i]>=0&&flag){
                flag=0;
                ans++;
            }
        }
        int k=b-num.sz;
        for(int i=0;i<now.sz;i++){
            int tmp=(now[i]-1);
            if(tmp==0)
                con;
            if(tmp<=k){
                k-=tmp;
                ans-=2;
            }
        }
        int l=now.back();
        int r=a-1;
        if(r-l>=k&&r-l!=0){
            ans--;
        }
        cout<<ans<<endl;
    }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[200005]={};
int main()
{
    int a,b;
    while(cin>>a>>b){
        vector<int>num;
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<a;i++){
            if(A[i]<0)
                num.push_back(i);
        }
        if(num.sz>b){
            cout<<-1<<endl;
            con;
        }
        vector<int>now;
        for(int i=0;i<num.sz-1;i++){
            now.push_back(num[i+1]-num[i]);
        }
        sort(now.begin(),now.end());
        int ans=0,flag=0;
        for(int i=0;i<a;i++){
            if(A[i]<0&&!flag){
                ans++;
                flag=1;
            }
            else if(A[i]>=0&&flag){
                flag=0;
                ans++;
            }
        }
        int k=b-num.sz;
        for(int i=0;i<now.sz;i++){
            int tmp=(now[i]-1);
            if(tmp==0)
                con;
            if(tmp<=k){
                k-=tmp;
                ans-=2;
            }
        }
        int l=0;
        for(int i=0;i<a;i++)
            if(A[i]<0)
                l=i;
        int r=a-1;
        if(r-l<=k&&r-l!=0){
            ans--;
        }
        cout<<ans<<endl;
    }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int temp[n+10];
    int winter = 0;
    for(int i = 0; i < n; i++){
        cin >> temp[i];
        if(temp[i] < 0){
            winter++;
        }
    }
    int ans = 0;
    if(winter > k){
        cout << -1 << endl;
        return 0;
    }else{
        int negativeSegments = 0;
        int lastSegmentL = 0;
        priority_queue<int,vector<int>,greater<int> >  segments;
        for(int i = 0; i < n; i++){
            if(temp[i] < 0){
                while(i<=n-1 && temp[i]<0){
                    i++;
                }
                negativeSegments++;

            }else{
                int count = 0;
                int j = i;
                while(i <= n-1 && temp[i] >= 0){
                    i++;
                    count++;
                }

                if(i!=n){
                    if(j!=0)segments.push(count);
                    //cout << count << endl;
                }else{
                    if(j!=0)lastSegmentL = count;
                }
            }
            i--;
        }
        //cout << negativeSegments << endl;
        int margin = k-winter;
        int ans = negativeSegments*2;
        if(ans == 0){
            cout << ans << endl;
            return 0;
        }
        while(margin > 0 && !segments.empty()){
            int current = segments.top();
            //cout << "current "<<current << endl;
            segments.pop();
            if(margin >= current){
                margin -= current;
            }else{
                break;
            }
            ans-=2;
        }
        if(margin >= lastSegmentL){
            ans-=1;
        }
        cout << ans << endl;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int temp[n+10];
    int winter = 0;
    for(int i = 0; i < n; i++){
        cin >> temp[i];
        if(temp[i] < 0){
            winter++;
        }
    }
    int ans = 0;
    if(winter > k){
        cout << -1 << endl;
        return 0;
    }else{
        int negativeSegments = 0;
        int lastSegmentL = 0;
        priority_queue<int,vector<int>,greater<int> >  segments;
        for(int i = 0; i < n; i++){
            if(temp[i] < 0){
                while(i<=n-1 && temp[i]<0){
                    i++;
                }
                negativeSegments++;

            }else{
                int count = 0;
                int j = i;
                while(i <= n-1 && temp[i] >= 0){
                    i++;
                    count++;
                }

                if(i!=n){
                    if(j!=0)segments.push(count);
                    //cout << count << endl;
                }else{
                    lastSegmentL = count;
                }
            }
            i--;
        }
        //cout << negativeSegments << endl;
        int margin = k-winter;
        int ans = negativeSegments*2;
        while(margin > 0){
            int current = segments.top();
            segments.pop();
            if(margin >= current){
                margin -= current;
            }else{
                break;
            }
            ans-=2;
        }
        if(margin >= lastSegmentL){
            ans-=1;
        }
        cout << ans << endl;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int temp[n+10];
    int winter = 0;
    for(int i = 0; i < n; i++){
        cin >> temp[i];
        if(temp[i] < 0){
            winter++;
        }
    }
    int ans = 0;
    if(winter > k){
        cout << -1 << endl;
        return 0;
    }else{
        int negativeSegments = 0;
        int lastSegmentL = 0;
        priority_queue<int,vector<int>,greater<int> >  segments;
        for(int i = 0; i < n; i++){
            if(temp[i] < 0){
                while(i<=n-1 && temp[i]<0){
                    i++;
                }
                negativeSegments++;

            }else{
                int count = 0;
                int j = i;
                while(i <= n-1 && temp[i] >= 0){
                    i++;
                    count++;
                }

                if(i!=n){
                    if(j!=0)segments.push(count);
                    //cout << count << endl;
                }else{
                    lastSegmentL = count;
                }
            }
            i--;
        }
        //cout << negativeSegments << endl;
        int margin = k-winter;
        int ans = negativeSegments*2;
        while(margin > 0 && !segments.empty()){
            int current = segments.top();
            //cout << "current "<<current << endl;
            segments.pop();
            if(margin >= current){
                margin -= current;
            }else{
                break;
            }
            ans-=2;
        }
        if(margin >= lastSegmentL){
            ans-=1;
        }
        cout << ans << endl;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int temp[n+10];
    int winter = 0;
    for(int i = 0; i < n; i++){
        cin >> temp[i];
        if(temp[i] < 0){
            winter++;
        }
    }
    int ans = 0;
    if(winter > k){
        cout << -1 << endl;
        return 0;
    }else{
        int negativeSegments = 0;
        int lastSegmentL = 0;
        priority_queue<int,vector<int>,greater<int> >  segments;
        for(int i = 0; i < n; i++){
            if(temp[i] < 0){
                while(i<=n-1 && temp[i]<0){
                    i++;
                }
                negativeSegments++;

            }else{
                int count = 0;
                int j = i;
                while(i <= n-1 && temp[i] >= 0){
                    i++;
                    count++;
                }

                if(i!=n){
                    if(j!=0)segments.push(count);
                    //cout << count << endl;
                }else{
                    lastSegmentL = count;
                }
            }
            i--;
        }
        //cout << negativeSegments << endl;
        int margin = k-winter;
        int ans = negativeSegments*2;
        while(margin > 0 && !segments.empty()){
            int current = segments.top();
            //cout << "current "<<current << endl;
            segments.pop();
            if(margin >= current){
                margin -= current;
            }else{
                break;
            }
            ans-=2;
        }
        if(margin >= lastSegmentL){
            ans-=1;
        }
        cout << (ans>0)?ans:0;
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra();
	for (int i=1; i<=n; i++) a[i]=ra();
	int last=0;
	for (int i=1; i<=n; i++)
	{
		if (a[i]<0) k--;
		if (a[i]>=0 && a[i-1]<0) last=i,ans++;
		if (a[i]>=0 && a[i+1]<0 && i!=1) b[++cnt]=i-last+1,ans++;
	}
	if (k<0)
	{
		cout<<"-1";
		return 0;
	}
	sort(b+1,b+cnt+1);
	if (a[1]<0) ans++;
	for (int i=1; i<=cnt; i++)
		if (k-b[i]<0) break;
			else k-=b[i],ans-=2;
	if (a[n]<0)
		for (int i=n; i>=1; i--)
			if (a[i]>=0)
			{
				b[++cnt]=n-i;
				break;
			}
	if (b[cnt]<=k && cnt) ans--;
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra();
	for (int i=1; i<=n; i++) a[i]=ra();
	int last=0;
	for (int i=1; i<=n; i++)
	{
		if (a[i]<0) k--;
		if (a[i]>=0 && a[i-1]<0) last=i,ans++;
		if (a[i]>=0 && a[i+1]<0 && last) b[++cnt]=i-last+1,ans++;
	}
	if (k<0)
	{
		cout<<"-1";
		return 0;
	}
	sort(b+1,b+cnt+1);
	if (a[1]<0) ans++;
	for (int i=1; i<=cnt; i++)
		if (k-b[i]<0) break;
			else k-=b[i],ans-=2;
	if (a[n]<0)
		for (int i=n; i>=1; i--)
			if (a[i]>=0)
			{
				b[++cnt]=n-i;
				break;
			}
	if (b[cnt]<=k) ans--;
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra(); a[1]=ra();
	if (a[1]<0) last=1,ans=1,k--;
	for (int i=2; i<=n; i++)
	{
		a[i]=ra();
		if (a[i]<0) k--;
		if ((a[i]<0 && a[i-1]>=0) || (a[i]>=0 && a[i-1]<0)) ans++;
		if (last && a[i]<0 && last!=i-1)
			b[++cnt]=i-last-1,last=i;
	}
		if (k<0)
		{
			cout<<"-1";
			return 0;
		}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
	{
		if (k-b[i]>=0) k-=b[i],ans-=2;
	}
	for (int i=n; i>=1; i--)
	{
		if (k<0) break;
		if (a[i]>=0) k--;
		if (a[i]<0)
		{
			ans--;
			break;
		 }
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra(); a[1]=ra();
	if (a[1]<0) last=1,ans=1,k--;
	for (int i=2; i<=n; i++)
	{
		a[i]=ra();
		if (a[i]<0) k--;
		if ((a[i]<0 && a[i-1]>=0) || (a[i]>=0 && a[i-1]<0)) ans++;
		if (last && a[i]<0 && last!=i-1)
			b[++cnt]=i-last-1,last=i;
	}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
	{
		if (k-b[i]>=0) k-=b[i],ans-=2;
	}
	for (int i=n; i>=1; i--)
	{
		if (k<0) break;
		if (a[i]>=0) k--;
		if (a[i]<0)
		{
			ans--;
			break;
		 }
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra(); a[1]=ra();
	if (a[1]<0) last=1,ans=1,k--;
	for (int i=2; i<=n; i++)
	{
		a[i]=ra();
		if (a[i]<0) k--;
		if ((a[i]<0 && a[i-1]>=0) || (a[i]>=0 && a[i-1]<0)) ans++;
		if (last && a[i]<0 && last!=i-1)
			b[++cnt]=i-last-1,last=i;
		if (k<0)
		{
			cout<<"-1";
			return 0;
		}
	}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
	{
		if (k-b[i]>=0) k-=b[i],ans-=2;
	}
	for (int i=n; i>=1; i--)
	{
		if (k<0) break;
		if (a[i]>=0) k--;
		if (a[i]<0)
		{
			ans--;
			break;
		 }
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra();
	for (int i=1; i<=n; i++) a[i]=ra();
	int last=0;
	for (int i=1; i<=n; i++)
	{
		if (a[i]<0) k--;
		if (a[i]>=0 && a[i-1]<0) last=i,ans++;
		if (a[i]>=0 && a[i+1]<0 && last) b[++cnt]=i-last+1,ans++;
	}
	if (k<0)
	{
		cout<<"-1";
		return 0;
	}
	sort(b+1,b+cnt+1);
	if (a[1]<0) ans++;
	for (int i=1; i<=cnt; i++)
		if (k-b[i]<0) break;
			else k-=b[i],ans-=2;
	if (a[n]<0)
		for (int i=n; i>=1; i--)
			if (a[i]>=0)
			{
				b[++cnt]=n-i;
				break;
			}
	if (b[cnt]<=k && cnt) ans--;
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra(); a[1]=ra();
	if (a[1]<0) last=1,ans=1,k--;
	for (int i=2; i<=n; i++)
	{
		a[i]=ra();
		if (a[i]<0) k--;
		if ((a[i]<0 && a[i-1]>=0) || (a[i]>=0 && a[i-1]<0)) ans++;
		if (last && a[i]<0 && last!=i-1)
			b[++cnt]=i-last-1,last=i;
	}
		if (k<0)
		{
			cout<<"-1";
			return 0;
		}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
	{
		if (k-b[i]>=0) k-=b[i],ans-=2;
	}
	if (a[n]>=0)
	for (int i=n; i>=1; i--)
	{
		if (k<0) break;
		if (a[i]>=0) k--;
		if (a[i]<0)
		{
			ans--;
			break;
		 }
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra();
	for (int i=1; i<=n; i++) a[i]=ra();
	int last,start;
	for (int i=1; i<=n; i++)
		if (a[i]<0) {
			start=i;
			break;
		}
	if (start<n) ans=1,k--;
	else {
		cout<<"0";
		return 0;
	}
	for (int i=start+1; i<=n; i++)
	{
		if (a[i]<0) k--;
		if (a[i]>=0 && a[i-1]<0) last=i,ans++;
		if (a[i]>=0 && a[i+1]<0) b[++cnt]=i-last+1,ans++;
	}
	if (k<0)
	{
		cout<<"-1";
		return 0;
	}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
		if (k-b[i]<0) break;
			else k-=b[i],ans-=2;
	if (a[n]>=0)
		for (int i=n; i>=1; i--)
			if (a[i]<0)
			{
				b[++cnt]=n-i;
				break;
			}
	if (b[cnt]<=k && cnt) ans--;
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra();
	for (int i=1; i<=n; i++) a[i]=ra();
	int last,start=n+1;
	for (int i=1; i<=n; i++)
		if (a[i]<0) {
			start=i;
			break;
		}
	if (start<=n) ans=1,k--;
	else {
		cout<<"0";
		return 0;
	}
	for (int i=start+1; i<=n; i++)
	{
		if (a[i]<0) k--;
		if (a[i]>=0 && a[i-1]<0) last=i,ans++;
		if (a[i]>=0 && a[i+1]<0) b[++cnt]=i-last+1,ans++;
	}
	if (k<0)
	{
		cout<<"-1";
		return 0;
	}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
		if (k-b[i]<0) break;
			else k-=b[i],ans-=2;
	if (a[n]>=0)
		for (int i=n; i>=1; i--)
			if (a[i]<0)
			{
				b[++cnt]=n-i;
				break;
			}
	if (b[cnt]<=k && cnt) ans--;
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra(); a[1]=ra();
	if (a[1]<0) last=1,ans=1;
	for (int i=2; i<=n; i++)
	{
		a[i]=ra();
		if (a[i]<0) k--;
		if ((a[i]<0 && a[i-1]>=0) || (a[i]>=0 && a[i-1]<0)) ans++;
		if (last && a[i]<0 && last!=i-1)
			b[++cnt]=i-last-1,last=i;
	}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
	{
		if (k-b[i]>0) k-=b[i],ans-=2;
	}
	for (int i=n-1; i>=1; i--)
	{
		if (a[i]>0 && k) k--;
		if (a[i]<0)
		{
			ans--;
			break;
		 }
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra();
	for (int i=1; i<=n; i++) a[i]=ra();
	int last,start;
	for (int i=1; i<=n; i++)
		if (a[i]<0) {
			start=i;
			break;
		}
	if (start<=n) ans=1,k--;
	else {
		cout<<"0";
		return 0;
	}
	for (int i=start+1; i<=n; i++)
	{
		if (a[i]<0) k--;
		if (a[i]>=0 && a[i-1]<0) last=i,ans++;
		if (a[i]>=0 && a[i+1]<0) b[++cnt]=i-last+1,ans++;
	}
	if (k<0)
	{
		cout<<"-1";
		return 0;
	}
	sort(b+1,b+cnt+1);
	for (int i=1; i<=cnt; i++)
		if (k-b[i]<0) break;
			else k-=b[i],ans-=2;
	if (a[n]>=0)
		for (int i=n; i>=1; i--)
			if (a[i]<0)
			{
				b[++cnt]=n-i;
				break;
			}
	if (b[cnt]<=k && cnt) ans--;
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
	int x=0,f=1; char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,k,last,ans,cnt;
int a[N<<1],b[N<<1];
int main()
{
	n=ra(); k=ra();
	for (int i=1; i<=n; i++) a[i]=ra();
	int last=0;
	for (int i=1; i<=n; i++)
	{
		if (a[i]<0) k--;
		if (a[i]*a[i-1]<0) ans++;
		if (a[i]>=0 && a[i-1]<0) last=i;
		if (a[i]>=0 && a[i+1]<0 && last) b[++cnt]=i-last+1;
	}
	if (k<0)
	{
		cout<<"-1";
		return 0;
	}
	sort(b+1,b+cnt+1);
	if (a[1]<0) ans++;
	for (int i=1; i<=cnt; i++)
		if (k-b[i]<0) break;
			else k-=b[i],ans-=2;
	if (a[n]<0)
		for (int i=n; i>=1; i--)
			if (a[i]>=0)
			{
				b[++cnt]=n-i;
				break;
			}
	if (b[cnt]<=k && cnt) ans--;
	cout<<ans;
	return 0;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.concurrent.ThreadLocalRandom;
import java.util.Random;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DesignTutorialLearnfromLife solver = new DesignTutorialLearnfromLife();
        solver.solve(1, in, out);
        out.close();
    }

    static class DesignTutorialLearnfromLife {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), capacity = in.nextInt();
            int[] floors = in.nextIntArray(0, n);
            Utils.shuffleArray(floors);
            Arrays.sort(floors);
            long answer = 0;
            for (int i = 0; ; i += capacity) {
                if (i + 2 * capacity >= n) {
                    answer += 2 * (floors[n - 1 - capacity] - 1);
                    answer += 2 * (floors[n - 1] - 1);
                    break;
                } else answer += 2 * (floors[i + capacity - 1] - 1);
            }
            out.println(answer);
        }

    }

    static class Utils {
        public static void shuffleArray(int[] arr) {
            Random random = ThreadLocalRandom.current();
            for (int i = arr.length - 1; i > 0; i--) {
                int index = random.nextInt(i + 1);
                int a = arr[index];
                arr[index] = arr[i];
                arr[i] = a;
            }
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int offset, int length) {
            int[] arr = new int[offset + length];
            for (int i = offset; i < offset + length; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Test {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        Scannerr in = new Scannerr(System.in);
        try (PrintWriter or = new PrintWriter(System.out)) {
            int n = in.nextInt(),k=in.nextInt();
           int [] a= new int[n];
            for (int i = 0; i < n; i++) {
                a[i]=in.nextInt()-1;
            }
           Arrays.sort(a);
           long ans=0;
            for (int i = n-1; i >-1; i-=k) {
                ans+=a[i]<<1;
            }
            or.print(ans);
        }
    }

    static class Scannerr {

        StringTokenizer st;
        BufferedReader br;

        public Scannerr(FileReader fileReader) throws FileNotFoundException {
            br = new BufferedReader(fileReader);
        }

        public Scannerr(InputStream s) throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++) {
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec) {
                        f *= 10;
                    }
                }
            }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.ni(), k = in.ni();
            Integer[] x = new Integer[n];
            for (int i = 0; i < n; i++) {
                x[i] = in.ni();
            }
            Arrays.sort(x, Collections.reverseOrder());
            int total = 0;
            for (int i = 0; i < n; i += k) {
                total += x[i] - 1;
            }
            out.println(total << 1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

    }
}


//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
//        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
//        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");

    }

    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            Arrays.sort(arr);
            int total = 0;
            for (int i = n - 1; i >= 0; i-=k) {
                total += 2 * (arr[i] - 1);
            }
            pw.println(total);
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException { return Double.parseDouble(next()); }

        public boolean ready() throws IOException {return br.ready();}
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Elevator{
    public static void main(String[] args) {
        MyScanner sc=new MyScanner();
        int n=sc.nextInt();
        int k=sc.nextInt();
        int arr[]=new int[n];
        for(int i=0;i<n;i++) arr[i]=sc.nextInt();
        int res=0;
        Arrays.sort(arr);
        for(int i=n-1;i>=0;i-=k){
            res+=2*(arr[i]-1);
        }
        System.out.println(res);
    }

    private static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class r_270_b {
 static StringTokenizer st;
 static BufferedReader br;
 static PrintWriter pw;

 public static void main(String[] args) throws IOException {
  Locale.setDefault(Locale.US);
  br = new BufferedReader(new InputStreamReader(System.in));
  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
    System.out)));
  int n=nextInt(),k=nextInt();
  int a[]=new int[n+1];
  for (int i = 1; i <=n; i++) {
   a[i]=nextInt();
  }
  /*ELDOR
   kod ni Dostondan oldim */
  Arrays.sort(a,1,n+1);
  int ans=0;
 for (int i = 1; i <=n; i+=k) {
  ans+=2*(a[i]-1);
 }
  pw.print(ans);
  pw.close();
 }

 private static void gfile() throws IOException {
  br = new BufferedReader(new FileReader(new File("input.txt")));
  pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(
    "output.txt"))));
 }

 private static int nextInt() throws IOException {
  return Integer.parseInt(next());
 }

 private static long nextLong() throws IOException {
  return Long.parseLong(next());
 }

 private static double nextDouble() throws IOException {
  return Double.parseDouble(next());
 }

 private static String next() throws IOException {
  while (st == null || !st.hasMoreTokens())
   st = new StringTokenizer(br.readLine());
  return st.nextToken();
 }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class r_270_b {
 static StringTokenizer st;
 static BufferedReader br;
 static PrintWriter pw;

 public static void main(String[] args) throws IOException {
  Locale.setDefault(Locale.US);
  br = new BufferedReader(new InputStreamReader(System.in));
  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
    System.out)));
  int n=nextInt(),k=nextInt();
  int a[]=new int[n+1];
  for (int i = 1; i <=n; i++) {
   a[i]=nextInt();
  }
  /*ELDOR
   kod ni Dostondan oldim */
  Arrays.sort(a,1,n+1);
  int ans=0;
 for (int i = n; i >=1; i-=k) {
  ans+=2*(a[i]-1);
 }
  pw.print(ans);
  pw.close();
 }

 private static void gfile() throws IOException {
  br = new BufferedReader(new FileReader(new File("input.txt")));
  pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(
    "output.txt"))));
 }

 private static int nextInt() throws IOException {
  return Integer.parseInt(next());
 }

 private static long nextLong() throws IOException {
  return Long.parseLong(next());
 }

 private static double nextDouble() throws IOException {
  return Double.parseDouble(next());
 }

 private static String next() throws IOException {
  while (st == null || !st.hasMoreTokens())
   st = new StringTokenizer(br.readLine());
  return st.nextToken();
 }
}


import java.util.*;
import java.io.*;

public class b {

    public static void main(String [] args) throws IOException{
       FastScanner sc=new FastScanner();
       int n=sc.nextInt();
       int k=sc.nextInt();
       int [] a=sc.nextIntArray(n);
       Arrays.sort(a);

       int ans=0;
       for(int i=n-1;i>=0;i-=k){
           ans+=2*(a[i]-1);
       }
       System.out.println(ans);

    }
}

class FastScanner{
    private int BUFFER_SIZE = 1 << 16;

   private  DataInputStream din;

   private  byte[] buffer;

   private int bufferPointer, bytesRead;

   public FastScanner() {
       din = new DataInputStream(System.in);
       buffer = new byte[BUFFER_SIZE];
       bufferPointer = bytesRead = 0;
   }

   public FastScanner( String file_name) throws IOException {
       din = new DataInputStream(new FileInputStream(file_name));
       buffer = new byte[BUFFER_SIZE];
       bufferPointer = bytesRead = 0;
   }

   public String readLine() throws IOException {
        byte[] buf = new byte[64];
       int cnt = 0, c;
       while ((c = read()) != -1) {
           if (c == '\n')
               break;
           buf[cnt++] = (byte) c;
       }
       return new String(buf, 0, cnt);
   }

   public String next() throws IOException{

       byte c = read();
       while(Character.isWhitespace(c)){
           c = read();
       }

        StringBuilder builder = new StringBuilder();
       builder.append((char)c);
       c = read();
       while(!Character.isWhitespace(c)){
           builder.append((char)c);
           c = read();
       }

       return builder.toString();
   }

   public int nextInt() throws IOException {
       int ret = 0;
       byte c = read();
       while (c <= ' ')
           c = read();
        boolean neg = (c == '-');
       if (neg)
           c = read();
       do {
           ret = ret * 10 + c - '0';
       } while ((c = read()) >= '0' && c <= '9');

       if (neg)
           return -ret;
       return ret;
   }

   public int[] nextIntArray( int n) throws IOException {
        int arr[] = new int[n];
       for(int i = 0; i < n; i++){
           arr[i] = nextInt();
       }
       return arr;
   }

   public long nextLong() throws IOException {
       long ret = 0;
       byte c = read();
       while (c <= ' ')
           c = read();
        boolean neg = (c == '-');
       if (neg)
           c = read();
       do {
           ret = ret * 10 + c - '0';
       } while ((c = read()) >= '0' && c <= '9');
       if (neg)
           return -ret;
       return ret;
   }

   public long[] nextLongArray( int n) throws IOException {
        long arr[] = new long[n];
       for(int i = 0; i < n; i++){
           arr[i] = nextLong();
       }
       return arr;
   }

   public char nextChar() throws IOException{
       byte c = read();
       while(Character.isWhitespace(c)){
           c = read();
       }
       return (char) c;
   }

   public double nextDouble() throws IOException {
       double ret = 0, div = 1;
       byte c = read();
       while (c <= ' ')
           c = read();
        boolean neg = (c == '-');
       if (neg)
           c = read();

       do {
           ret = ret * 10 + c - '0';
       } while ((c = read()) >= '0' && c <= '9');

       if (c == '.') {
           while ((c = read()) >= '0' && c <= '9') {
               ret += (c - '0') / (div *= 10);
           }
       }

       if (neg)
           return -ret;
       return ret;
   }

   public double[] nextDoubleArray( int n) throws IOException {
        double arr[] = new double[n];
       for(int i = 0; i < n; i++){
           arr[i] = nextDouble();
       }
       return arr;
   }

   private void fillBuffer() throws IOException {
       bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
       if (bytesRead == -1)
           buffer[0] = -1;
   }

   private byte read() throws IOException {
       if (bufferPointer == bytesRead)
           fillBuffer();
       return buffer[bufferPointer++];
   }

   public void close() throws IOException {
       if (din == null)
           return;
       din.close();
   }

}


import java.io.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
public class Temp3 {
	public static void main(String[] args) throws Throwable {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());
		int[] arr = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++)
		{
			arr[i] = Integer.parseInt(st.nextToken());
		}
		Arrays.sort(arr);
		int ind = n - 1;
        int ans = 0;
        while (ind >= 0)
        {
            int max = 0;
            for (int i = 0; i < k && ind >= 0; i++)
            {
                max = Math.max(max, arr[ind--]);
            }
            ans += (2 * max) - 2;
        }
		System.out.println(ans);
	}
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 *
 * @author RezaM
 */
public class B {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strt = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(strt.nextToken());
        int k = Integer.parseInt(strt.nextToken());

        StringTokenizer stt = new StringTokenizer(br.readLine());
        TreeMap<Integer, Integer> tp = new TreeMap<Integer, Integer>();

        for (int i = 0; i < n; i++) {
            int number = Integer.parseInt(stt.nextToken());

            if (tp.containsKey(number)) {
                int lval = tp.get(number);
                tp.replace(number, lval + 1);
            } else {
                tp.put(number, 1);
            }

        }

        long result = 0;

        while (!tp.isEmpty()) {

            int cpas = 0;

            long time = tp.lastKey();

            while (cpas != k && !tp.isEmpty()) {

                int bkey = tp.lastKey();
                int value = tp.get(bkey);

                if (value - (k - cpas) > 0) {

                    tp.replace(bkey, value - (k - cpas));
                    cpas = k;
                } else if (value - (k - cpas) == 0) {
                    cpas = k;
                    tp.remove(bkey);
                } else if (value - (k - cpas) < 0) {
                    cpas += value;
                    tp.remove(bkey);
                }

            }

            result += (long) 2 * (time - 1);

        }

        System.out.println(result);
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 *
 * @author RezaM
 */
public class B {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strt = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(strt.nextToken());
        int k = Integer.parseInt(strt.nextToken());

        StringTokenizer stt = new StringTokenizer(br.readLine());
        TreeMap<Integer, Integer> tp = new TreeMap<Integer, Integer>();

        for (int i = 0; i < n; i++) {
            int number = Integer.parseInt(stt.nextToken());

            if (tp.containsKey(number)) {
                int lval = tp.get(number);
                tp.replace(number, lval + 1);
            } else {
                tp.put(number, 1);
            }

        }

        long result = 0;

        while (!tp.isEmpty()) {

            int cpas = 0;

            int time = tp.lastKey();

            while (cpas != k && !tp.isEmpty()) {

                int bkey = tp.lastKey();
                int value = tp.get(bkey);

                if (value - (k - cpas) > 0) {
                    cpas = k;
                    tp.replace(bkey, value - k);
                } else if (value - (k - cpas) == 0) {
                    cpas = k;
                    tp.remove(bkey);
                } else if (value - (k - cpas) < 0) {
                    cpas += value;
                    tp.remove(bkey);
                }

            }

            result += 2 * (time - 1);

        }

        System.out.println(result);
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 *
 * @author RezaM
 */
public class B {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strt = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(strt.nextToken());
        int k = Integer.parseInt(strt.nextToken());

        StringTokenizer stt = new StringTokenizer(br.readLine());
        TreeMap<Integer, Integer> tp = new TreeMap<Integer, Integer>();

        for (int i = 0; i < n; i++) {
            int number = Integer.parseInt(stt.nextToken());

            if (tp.containsKey(number)) {
                int lval = tp.get(number);
                tp.replace(number, lval + 1);
            } else {
                tp.put(number, 1);
            }

        }

        long result = 0;

        while (!tp.isEmpty()) {

            int cpas = 0;

            long time = tp.lastKey();

            while (cpas != k && !tp.isEmpty()) {

                int bkey = tp.lastKey();
                int value = tp.get(bkey);

                if (value - (k - cpas) > 0) {
                    cpas = k;
                    tp.replace(bkey, value - k);
                } else if (value - (k - cpas) == 0) {
                    cpas = k;
                    tp.remove(bkey);
                } else if (value - (k - cpas) < 0) {
                    cpas += value;
                    tp.remove(bkey);
                }

            }

            result += (long)2 * (time - 1);

        }

        System.out.println(result);
    }
}


import java.util.*;
import java.io.*;

public class elevator {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int cap = in.nextInt();
		ArrayList<Integer> arr = new ArrayList<>();
		for(int i = 0; i < n; i++)
			arr.add(in.nextInt());
		Collections.sort(arr);

		int res = 0;
		int currFloor = 1;;
		while(!arr.isEmpty()) {
			int floor = arr.get(0);
			//System.out.println("floor: "+floor);
			//System.out.println("currfloor: "+currFloor);
			//take everyone to that floor
			int dist = 0;
			if(arr.size() <= cap)
				dist = floor-currFloor;
			else
				dist = (int) ((Math.ceil((double)arr.size()/cap)*2-1)*(floor-currFloor));
			res+=dist;
			//System.out.println("taking everyone there: "+dist);
			//remove the guy
			arr.remove(0);
			currFloor = floor;
		}
		//back to first floor
		res+=currFloor-1;
		System.out.println(res);

	}

}


import java.util.*;
public class LearnFromLife {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++){
			arr[i] = in.nextInt();
		}
		int sum = 0;
		for (int i = n-1; i >= 0; i-=k){
			sum += 2 * (arr[i] - 1);
		}
		System.out.println(sum);
	}

}


import java.util.*;
public class LearnFromLife {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++){
			arr[i] = in.nextInt();
		}
		Arrays.sort(arr);
		int sum = 0;
		for (int i = n-1; i >= 0; i-=k){
			sum += 2 * (arr[i] - 1);
		}
		System.out.println(sum);
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.math.BigInteger;

public class b270 {

	static class TaskA
    {
        public void solve(int testNumber, InputReader in, PrintWriter out)
        {
        	int n=in.nextInt();
        	int k=in.nextInt();
        	int index=0;
        	int sum=0;
        	int arr[]=new int[n];
        	for(int i=0;i<n;i++){
        		arr[i]=in.nextInt();
        	}
        	Arrays.sort(arr);
        	for(int i=n-1;i>=0;i-=k)
        	{
        		sum+=2*(arr[i]-1);
       // 		index=i;

        	}
       // 	sum+=2*(arr[index])-1;
        	out.println(sum);
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static int binarysearch(int[] a, int start, int end, int x) {
		if (x < a[start]) return start;
		if (x >= a[end]) return end+1;
		int mid = (start + end)/2;
		if (x < a[mid]) return binarysearch(a, start, mid, x);
		else return binarysearch(a, mid+1, end, x);
	}

    static void radixSort(int[] xs){
		int[] cnt = new int[(1<<16)+1];
		int[] ys = new int[xs.length];
		for(int j = 0; j <= 16; j += 16)
		{	Arrays.fill(cnt, 0);
			for(int x : xs) { cnt[(x>>j&0xFFFF)+1]++; }
			for(int i = 1; i < cnt.length; i++) { cnt[i] += cnt[i-1]; }
			for(int x : xs) { ys[cnt[x>>j&0xFFFF]++] = x; }
			{ final int[] t = xs; xs = ys; ys = t; }   }
		if(xs[0] < 0 || xs[xs.length - 1] >= 0)
			return;
		int i, j, c;
		for(i = xs.length - 1, c = 0; xs[i] < 0; i--, c++) { ys[c] = xs[i]; }
		for(j = xs.length - 1; i >= 0; i--, j--) { xs[j] = xs[i]; }
		for(i = c - 1; i >= 0; i--) { xs[i] = ys[c-1-i]; }
	}

    static long min(long x,long y){return x<y?x:y;}
    static long min(long x,long y,long z){return x<y?(x<z?x:z):(y<z?y:z);}
    static long min(long n1,long n2,long n3,long n4){
    	return n1<n2?(n1<n3?(n1<n4?n1:n4):(n3<n4?n3:n4)):(n2<n3?(n2<n4?n2:n4):(n3<n4?n3:n4));}
    static long max(long x,long y){return x>y?x:y;}
    static long max(long x,long y,long z){return x>y?(x>z?x:z):(y>z?y:z);}
    static long max(long n1,long n2,long n3,long n4){
    	return n1>n2?(n1>n3?(n1>n4?n1:n4):(n3>n4?n3:n4)):(n2>n3?(n2>n4?n2:n4):(n3>n4?n3:n4));}
    static int min(int x,int y){return x<y?x:y;}
    static int min(int x,int y,int z){return x<y?(x<z?x:z):(y<z?y:z);}
    static long min(int n1,int n2,int n3,int n4){
    	return n1<n2?(n1<n3?(n1<n4?n1:n4):(n3<n4?n3:n4)):(n2<n3?(n2<n4?n2:n4):(n3<n4?n3:n4));}
    static int max(int x,int y){return x>y?x:y;}
    static int max(int x,int y,int z){return x>y?(x>z?x:z):(y>z?y:z);}
    static long max(int n1,int n2,int n3,int n4){
    	return n1>n2?(n1>n3?(n1>n4?n1:n4):(n3>n4?n3:n4)):(n2>n3?(n2>n4?n2:n4):(n3>n4?n3:n4));}

    static long sumarr(int arr[],int n1,int n2){
    	long sum=0; for(int i=n1-1;i<n2;i++) sum=sum+arr[i];  return sum; }

//**************************************Reader Class*********************************************//

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
        	return Long.parseLong(next());
        }

        public double nextDouble() {
        	return Double.parseDouble(next());
        }

    }
}


import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;

public class ElevatorProblem {

     public static void main(String []args){
        Scanner input = new Scanner(System.in);

        Vector<Integer> v = new Vector<Integer>();
        int n, k;
        int totalSeconds = 0;

        n = input.nextInt();
        k = input.nextInt();
        for (int i = 0; i < n; ++i)
            v.add(input.nextInt());

        Collections.sort(v);

        totalSeconds = v.get(v.size() - 1) - 1;

        int x = 0;
        double z = k;
        double y;
        int temp = 0;
        while(!v.isEmpty()) {
            y = v.size() / z;
            x = (int)Math.ceil(y);
            totalSeconds += (v.get(0) - 1) * x + (v.get(0) - 1) * (x -1);

            temp = v.get(0);
            for (int i = 0; i < v.size(); i++) {
                v.set(i, v.get(i) - (temp - 1));

            }
            for (int i = 0; i < v.size(); i++) {
                if (v.get(i) == 1)
                   v.remove(i);
                else
                   break;
            }
        }
        System.out.println(  totalSeconds);
     }
}


import java.util.*;

public class Test {

    static boolean haveFoundName(HashMap map, String name) {

        return true;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        int sol = 0;

        int[] f = new int[n];

        for (int i = 0; i < n; i++) {
            f[i] = sc.nextInt();
        }

        //sort
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < n; j++) {
                if (f[j-1] > f[j]) {
                    int t = f[j-1];
                    f[j-1] = f[j];
                    f[j] = t;
                }
            }
        }

        int peopleLeft = n;

        int i = n%k == 0 ? 1 : 0;

        for (; i < n/k+1; i++) {
            peopleLeft -= k;

            int ss = n%k + i*k - 1;

            sol += 2*(f[ss] - 1);

//            System.out.println(ss);
        }

//        for (int i=1; peopleLeft >= k; i++) {
//            peopleLeft -= k;
//
//            if (k*i - peopleLeft > 0) {
//                sol += 2*(f[k*i-peopleLeft-1]-1);
//            }
//            else {
//                sol += 2*(f[k*i-1]-1);
//            }
//        }
//
//        if (peopleLeft > 0) {
//            sol += 2*(f[n-1]-1);
//        }

        System.out.println(sol);
    }
}


import java.util.*;

public class Test {

    static boolean haveFoundName(HashMap map, String name) {

        return true;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        int sol = 0;

        int[] f = new int[n];

        for (int i = 0; i < n; i++) {
            f[i] = sc.nextInt();
        }

        //sort
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < n; j++) {
                if (f[j-1] > f[j]) {
                    int t = f[j-1];
                    f[j-1] = f[j];
                    f[j] = t;
                }
            }
        }

        int peopleLeft = n;

//        for (int i=1; peopleLeft >= k; i++) {
//            peopleLeft -= k;
//
//            if (peopleLeft < 0) {
//                sol += 2*(f[n-1]-1);
//            }
//            else {
//                sol += 2*(f[n-peopleLeft-1]-1);
//            }
//        }

        for (int i=1; peopleLeft >= k; i++) {
            peopleLeft -= k;

            if (k*i - peopleLeft > 0) {
                sol += 2*(f[k*i-peopleLeft-1]-1);
            }
            else {
                sol += 2*(f[k*i-1]-1);
            }
        }

        if (peopleLeft > 0) {
            sol += 2*(f[n-1]-1);
        }

        System.out.println(sol);
    }
}


import java.util.*;

public class Test {

    static boolean haveFoundName(HashMap map, String name) {

        return true;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        int sol = 0;

        int[] f = new int[n];

        for (int i = 0; i < n; i++) {
            f[i] = sc.nextInt();
        }

        //sort
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < n; j++) {
                if (f[j-1] > f[j]) {
                    int t = f[j-1];
                    f[j-1] = f[j];
                    f[j] = t;
                }
            }
        }

        int peopleLeft = n;

        int i = n%k == 0 ? 1 : 0;

        for (; i < n/k+1; i++) {
            peopleLeft -= k;

            int ss = n%k + i*k - 1;

            sol += 2*(f[ss] - 1);

            System.out.println(ss);
        }

//        for (int i=1; peopleLeft >= k; i++) {
//            peopleLeft -= k;
//
//            if (k*i - peopleLeft > 0) {
//                sol += 2*(f[k*i-peopleLeft-1]-1);
//            }
//            else {
//                sol += 2*(f[k*i-1]-1);
//            }
//        }
//
//        if (peopleLeft > 0) {
//            sol += 2*(f[n-1]-1);
//        }

        System.out.println(sol);
    }
}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.math.*;

public class JavaApplication14{

    public static void main(String[] args) throws IOException,NumberFormatException
    {

        try
      {
           int l=0;
           int time=0;
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int a[]= new int[n];

        int cp =sc.nextInt();
        int c[] = new int[cp];
        for(int k=0;k<n;k++)
          a[k]=sc.nextInt();
            int y=0;
                ///insertion sort
          for(int j=0;j<n;j++)
          {
              int temp=0;               ////k is to be inserted in proper place

              for( l=j; l<n;l++)
              { if(a[l]>a[j])
              { temp=a[l];
                  a[l]=a[j];
                a[j]=temp;}
              }
          }

          for(int d=0;d<n;d++)

                 y=0;
             while(y<n)
             {
              time=time+(a[y]-1)*2;

                 y=y+cp;
             }
             int p=y-cp;
             if(p<n-1)
               time=time+(a[n-1]-1)*2;

      System.out.println(time);

      }
        catch(Exception e)
        {
            System.out.println("");
        }

    }

}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.math.*;

public class JavaApplication14{

    public static void main(String[] args) throws IOException,NumberFormatException
    {
   try
      {
           int l=0; int time=0;int y=0;
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int a[]= new int[n];
        int cp =sc.nextInt();
        int c[] = new int[cp];

          for(int k=0;k<n;k++)
          a[k]=sc.nextInt();

                ///insertion sort
          for(int j=0;j<n;j++)
          {
            int temp=0;               ////k is to be inserted in proper place
            for( l=j; l<n;l++)
              { if(a[l]>a[j])
                    { temp=a[l];
                       a[l]=a[j];
                       a[j]=temp;}
              }
          }
          if(cp>=n){time=time+(a[0]-1)*2;}
          else{
            while(y<n){time=time+(a[y]-1)*2;y=y+cp;}}

             System.out.println(time);

      }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }

    }

}