#include <cstdio>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include <map>
#define ll long long
using namespace std;
int N,K,ans,cnt;
int num=1;
deque<pair<int,int>> belt; 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N >> K;
    for(int i=0;i<2*N;i++)
    {
        int a;
        cin >> a;
        belt.push_back({0,a});
    }
    while(true)
    {
        ans++;
        
        auto tmp = belt.back(); belt.pop_back();
        belt.push_front(tmp);
        belt[0].first = 0; 
        
        belt[N-1].first = 0;
        for(int i=N-2;i>=0;i--)
        {
            if(belt[i].first == 0) continue;
            if(belt[i+1].first == 0 and belt[i+1].second > 0){
                belt[i+1].second--;
                belt[i+1].first = belt[i].first;
                belt[i].first = 0;
            }
        }
        
        if(belt[0].second > 0)
        {
            belt[0].first = num++;
            belt[0].second--;
        }
        int cur_cnt = 0;
        
        for(int i=0;i<2*N;i++)
            if(belt[i].second == 0) cur_cnt++;
        if(cur_cnt >= K) break;
    }
    cout << ans;
    return 0;
}