#include <bits/stdc++.h>
using  namespace std;
int s[1000001];
int main() {

int n,x;
cin >> n >> x;

for( int x = 1 ; x <= n ; x++ )
{
    cin >> s[x];
}

sort( s+1, s + 1000001, greater<int>() );

cout << s[1]- x;





return 0;
}