#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    int minn=0,maxx=0;
    cin>>a>>b;
    for(int i=0;i<a;i++){
        cin>>b;
        if(b-a<minn){
            minn=b;
        }
           if(b-a>maxx){
            maxx=b;
        }
    }
    cout<<minn*2+maxx;
}