object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val sz = sc.nextInt
    val list = List.fill(sz)(sc.nextInt)
    val max = list.max
    val max_index = list.indexOf(max)
    val min = list.min
    val min_index = list.indexOf(min)
    val ret = if(max_index<min_index) min - max else max - min
    println(ret)
  }
}