$num=<>;chomp $num;$input=<>;chomp $input;
@houses = split / /, $input;
@houses = sort { int($a) <=> int($b) } @houses;
$prev = pop @houses;
$len = 0;
while ($h = pop @houses) {
    $len += $prev - $h;
    $prev = $h;
}

print $len;