#include <bits/stdc++.h>
bool v[1005];
int a[1005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    v[a[i]] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= 1000; i++) {
    if (v[i]) a[cnt++] = i;
  }
  int minn = 100000000;
  for (int i = 0; i < cnt; i++) {
    int ans = a[i] - a[0];
    ans += a[cnt - 1] - a[i];
    if (ans < minn) minn = ans;
  }
  printf("%d\n", minn);
  return 0;
}
