N = gets.to_i a = gets.split.map(&:to_i) _, ans = a.inject([0, 0]) {|(m, k), x| [[m, x].max, x < m ? [k, x].max : k]} puts ans