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