N = int(input())
As = list(map(int, input().split()))

hs = []
ls = []

i = 0
if As[1] > As[0]:
  ls.append((As[0],0))
  f = 1
elif As[1] < As[0]:
  hs.append((As[0],0))
  f = 0
else:
  fl = 1
  for j in range(2,N):
    if As[j] > As[0]:
      ls.append((As[0],0))
      f = 1
      i = j
      fl = 0
      break
    elif As[j] < As[0]:
      hs.append((As[0],0))
      f = 0
      i = j
      fl = 0
      break
  if fl == 1:
    print(1000)
    exit()
  
while i < N-1:
  if f == 1 and As[i] > As[i+1]:
    hs.append((As[i],i))
    f = 0
  elif f == 0 and As[i] < As[i+1]:
    ls.append((As[i],i))
    f = 1
  i += 1
    
if As[N-2] < As[N-1]:
  hs.append((As[N-1],N-1))
elif As[N-2] > As[N-1]:
  ls.append((As[N-1],N-1))

if len(ls) == 1 and len(hs) == 1 and ls[0][1] > hs[0][1]:
  print(1000)
  exit()
if ls[0][1] > hs[0][1]:
  del hs[0]
if hs[-1][1] < ls[-1][1]:
  del ls[-1]