n, k = map(int, input().split())
spis = list(map(int, input().split()))
fir = 0
sec = 0
f = 1
s = 1
cur = 0
ind1 = -1
ind2 = -1
sost = True
for i in range(n):
    if (spis[i]>fir and (sost or spis[i]<=sec)):
        fir = f+spis[i]+cur
        cur = 0
        f+=1
        sost = False
        ind1=i
    elif (spis[i]>sec):
        sec = s+spis[i]+cur
        s+=1
        cur = 0
        sost = True
        ind2=i
    else:
        cur+=1
for i in range(max(ind1, ind2)+1, n):
    fir = max(fir, spis[i]+f+(i-max(ind1, ind2)))
    sec = max(sec, spis[i]+s+(i-max(ind1, ind2)))

ans = fir+sec
print(ans)


