input();a=sorted(set(map(int,input().split()))) print(abs(a[-1]-a[-2]))