#import <Foundation/Foundation.h>
int compare_int(const void*a, const void*b){
	return *((int*)b)-*((int*)a);
}
int main() {
	int k,t;
	scanf("%d %d",&k,&t);
	if(k==1){
		puts("0");
		return 0;
	}
	if(t==1){
		printf("%d\n",k-1);
		return 0;
	}
	int *a = (int*)malloc(sizeof(int)*t);
	for(int i=0;i<t;i++){
		scanf("%d",a+i);
	}
	qsort(a, t, sizeof(int), compare_int);
	printf("%d\n", MAX(a[0]-1-(k-a[0]),0));
}
