'use strict';

let lines = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const N = +lines[0];
if (N == 1) {
    console.log(0);
    process.exit();
}
const as = lines[1].split(' ').sort();
console.log(as.pop() - as.shift());