#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cerr.tie(0);
    cout.tie(0);
    int n, k, br = 0;
    cin >> n >> k;
    vector<int> napitci(n);
    for (int i = 0; i < n; i++)
        cin >> napitci[i];
    if (k == 2)
        cout << *max_element(napitci.begin(), napitci.end()) - *min_element(napitci.begin(), napitci.end()) << endl;
    return 0;
}