local n, t = io.read("*n", "*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local mmi, mma = math.min, math.max
local min = {}
min[1] = {}
min[1].c, min[1].v = 1, a[1]

for i = 2, n do
  min[i] = {}
  if a[i] < min[i - 1].v then
    min[i].c, min[i].v = 1, a[i]
  elseif min[i - 1].v == a[i] then
    min[i].c = min[i - 1].c + 1
    min[i].v = min[i - 1].v
  else
    min[i].c = min[i - 1].c
    min[i].v = min[i - 1].v
  end
end
local maxrate = 0
for i = 2, n do
  maxrate = mma(maxrate, a[i] - min[i].v)
end
local totcnt = 0
local mincnt = min[1].c
local maxcnt = 0
for i = 2, n do
  if min[i].v < min[i - 1].v then
    totcnt = totcnt + mmi(mincnt, maxcnt)
    mincnt = min[i].c
    maxcnt = 0
  else
    if maxrate == a[i] - min[i].v then
      maxcnt = maxcnt + 1
    end
  end
end
totcnt = totcnt + mmi(mincnt, maxcnt)
print(totcnt)
