#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int K,T;
  cin>>K>>T;
  vector<int> A(T);
  for(int i(0);i<T;i++){
    cin>>A[i];
  }
  sort(A.rbegin(),A.rend());
  int sum(0);
  if(T == 1){
    cout << A[0] - 1 << endl;
  }else{
    for(int i(1);i<T;i++){
      sum += A[i];
    }
    cout << max(A[0]-sum-1,0) << endl;
  }
}


#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;


int main(){
    int k,t;
    cin >> k >> t;
    multiset<int> s;
    rep(i,t){
        int temp;
        cin >> temp;
        s.insert(temp);
    }
    int st = 0;
    rep(i,k){
        if(s.size()==0){
            cout << st << endl;
            return 0;
        }
 
 
        int temp = *(--s.end());
        --temp;
        //cout << " " << temp << endl;
        s.erase(--s.end());
        //cout << "  " << s.size() << endl;
        if(st>0&&i>0) s.insert(st);
        st = temp;
    }

    cout << 0 << endl;
}