function compareFunc(a, b) {
  return a - b;
}

function main(input) {
  let inputs = input.split(/\n/);
  let args = inputs[1].split(/\s/);
  args.sort(compareFunc);
  console.log(args[1] - args[0]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));