n = gets.to_i
a = gets.chomp.split.map(&:to_i) + [0]
b = [0]
a.each{|x| b << x if x != b.last}

h = Hash.new{|h, k| h[k] = [0, 0]}
for x in 1...(b.length - 1)
    if b[x] > b[x - 1] && b[x] > b[x + 1]
        h[b[x]][0] += 1
    elsif b[x] < b[x - 1] && b[x] < b[x + 1]
        h[b[x]][1] += 1
    end
end
h.delete(0)

count, max = 0, 0
h.keys.sort.reverse_each{|k|
    count += h[k][0] - h[k][1]
    max = count if max < count
}
puts max
