package main

import (
    "fmt"
)

type Solution struct {
    prices []int
}

func (t Solution) getMaxProfit() int {
    max_profit := 0
    min_price := t.prices[0]
    for _,p := range t.prices {
        max_profit = max(max_profit, p - min_price)
        min_price = min(min_price, p)
    }
    return max_profit
}

func max(a int, b int) int {
    if a > b {
        return a
    }
    return b
}

func min(a int, b int) int {
    if a < b {
        return a
    }
    return b
}

func main() {
    n := 0
    fmt.Scan(&n)
    prices := []int{}
    for n >=1 {
        p := 0
        fmt.Scan(&p)
        prices = append(prices, p)
        n--
    }
    fmt.Print(Solution{prices}.getMaxProfit())
}