mov (x0,l,r) x1 =
  if x0 == x1
  then (x0,l,r)
  else if x0 < x1
       then if r == 0
            then (x1,l+1,r)
            else (x1,l+1,r-1)
       else if l == 0
            then (x1,l,r+1)
            else (x1,l-1,r+1)

ans (x0:xs) =
  let (x,l,r) = foldl mov (x0,0,0) xs
  in
    1+l+r

main = do
  _ <- getLine
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = ans i
  print o

