#include <bits/stdc++.h>
using namespace std;
map<int, bool> m;
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (m[x])
      continue;
    else {
      a.push_back(x);
      m[x] = 1;
    }
  }
  if (a.size() == 1)
    cout << 0;
  else {
    int ans = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i < a.size() - 1; i++) ans += a[i + 1] - a[i];
    cout << ans;
  }
}
