n = gets.to_i
h = gets.chomp.split.map(&:to_i)

m = h.max

h.insert(0, m)
h.push(m)

c = 0
while true
  a = h.each_with_index.select{|e, i| e == m}.map{|e| e[1]}
  break if a.length == h.length
  (a.length-1).times do |i|
    next if a[i + 1] - a[i] == 1
    s = a[i] + 1
    e = a[i+1] - 1
    h[s..e] = h[s..e].map{|i| i + 1}
    c += 1
  end
end

puts c