#!/bin/python3 import sys n = int(input().strip()) a = list(map(int, input().strip().split(' '))) # your code goes here max1 = a[0] for i in range(n): max1 = max(max1, a[i]) a.remove(max1) max2 = a[0] for i in range(n-1): max2 = max(max2, a[i]) print(abs(max1-max2))