#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int k,t; cin >> k >> t;
  int mx = 0;
  vi a(t);
  rep(i,t){
    cin >> a[i];
    chmax(mx,a[i]);
  }
  if((k+1)/2 < mx){
    cout << (mx-(k+1)/2)*2-1;
  }else{
    cout << 0;
  }
  cout << "\n";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    int white_cnt = 0;
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
        for (int j = 0; j < w; j++)
        {
            if(s[i][j] == '.')white_cnt++;
        }
    }

    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};

    vector<vector<int>> seen(h, vector<int>(w, -1));
    queue<pair<int, int>> que;

    seen[0][0] = 0;
    que.push(make_pair(0, 0));

    while (!que.empty())
    {
        pair<int ,int> pos = que.front();
        int x = pos.first, y = pos.second;
        que.pop();

        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            
            if(nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
            if(s[nx][ny] == '#')continue;

            if(seen[nx][ny] == -1)
            {
                que.push(make_pair(nx, ny));
                seen[nx][ny] = seen[x][y] + 1;
            }
        }
    }

    if(seen[h - 1][w - 1] == -1)cout << -1 << endl;
    else cout << white_cnt - seen[h - 1][w - 1] - 1 << endl;
}