import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int K, T; scanf("%d %d\n", &K, &T);
    auto A = readln.chomp.split(" ").map!(to!int).array;
    BinaryHeap!(Array!int, "a < b") Q;
    foreach (a; A) Q.insert(a);
    while (Q.length >= 2) {
        auto x = Q.front; Q.popFront;
        auto y = Q.front; Q.popFront;
        Q.insert(x - y);
    }
    writeln(max(0, Q.front - 1));
}
