# coding: utf-8

# Your code here!



import sys

sys.setrecursionlimit(10**6)

readline = sys.stdin.readline

 

#n = int(input())

n,t = [int(i) for i in readline().split()]

a = [10**9+1]+[int(i) for i in readline().split()]





"""

gain = 0

m = 0

maxid = []

minid = []

memo = {}

for i in range(n-1,-1,-1):

    ai = a[i]

    if ai > m:

        m = ai

        maxid = [i]

        memo.append([minid[:],maxid[:]])

    elif ai == m:

        maxid.append[i]



    m = max(ai,m)

    if gain < m-ai:

        gain = m-ai

        minid = [i]

        memo = []

    elif gain == m-ai:

        minid.append(i)

    

    print(minid,maxid,memo)

"""    



gain = 0

m = 0

for ai in reversed(a):

    m = max(ai,m)

    if gain < m-ai: gain = m-ai



m = 0

mi = ma = 0



ans = 0

for ai in reversed(a):

    if m < ai:

        ans += max(mi,ma)

        mi = ma = 0

    elif m == ai:

        ma += 1



    m = max(m,ai)

    

    if m-ai == gain:

        mi += 1





print(ans)    









# coding: utf-8

# Your code here!



import sys

sys.setrecursionlimit(10**6)

readline = sys.stdin.readline

 

#n = int(input())

n,t = [int(i) for i in readline().split()]

a = [int(i) for i in readline().split()]



m = gain = 0

ans = 0

for ai in reversed(a):

    m = max(ai,m)

    if gain < m-ai:

        ans = 1

    elif gain == m-ai:

        ans += 1

    gain = max(gain,m-ai)



print(ans)    









# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
# n = int(input())
n, t = [int(i) for i in readline().split()]
a = [10**9 + 1] + [int(i) for i in readline().split()]
"""
gain = 0
m = 0
maxid = []
minid = []
memo = {}
for i in range(n-1,-1,-1):
    ai = a[i]
    if ai > m:
        m = ai
        maxid = [i]
        memo.append([minid[:],maxid[:]])
    elif ai == m:
        maxid.append[i]
    m = max(ai,m)
    if gain < m-ai:
        gain = m-ai
        minid = [i]
        memo = []
    elif gain == m-ai:
        minid.append(i)
    print(minid,maxid,memo)
"""
gain = 0
m = 0
for ai in reversed(a):
    m = max(ai, m)
    if gain < m - ai:
        gain = m - ai
m = 0
mi = ma = 0
ans = 0
for ai in reversed(a):
    if m < ai:
        ans += max(mi, ma)
        mi = ma = 0
    elif m == ai:
        ma += 1
    m = max(m, ai)
    if m - ai == gain:
        mi += 1
print(ans)

# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
# n = int(input())
n, t = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]
m = gain = 0
ans = 0
for ai in reversed(a):
    m = max(ai, m)
    if gain < m - ai:
        ans = 1
    elif gain == m - ai:
        ans += 1
    gain = max(gain, m - ai)
print(ans)

-a = [10**9 + 1] + [int(i) for i in readline().split()] -""" -gain = 0 -m = 0 -maxid = [] -minid = [] -memo = {} -for i in range(n-1,-1,-1): -    ai = a[i] -    if ai > m: -        m = ai -        maxid = [i] -        memo.append([minid[:],maxid[:]]) -    elif ai == m: -        maxid.append[i] -    m = max(ai,m) -    if gain < m-ai: -        gain = m-ai -        minid = [i] -        memo = [] -    elif gain == m-ai: -        minid.append(i) -    print(minid,maxid,memo) -""" -gain = 0 -m = 0 +a = [int(i) for i in readline().split()] +m = gain = 0 +ans = 0 -        gain = m - ai -m = 0 -mi = ma = 0 -ans = 0 -for ai in reversed(a): -    if m < ai: -        ans += max(mi, ma) -        mi = ma = 0 -    elif m == ai: -        ma += 1 -    m = max(m, ai) -    if m - ai == gain: -        mi += 1 +        ans = 1 +    elif gain == m - ai: +        ans += 1 +    gain = max(gain, m - ai)