import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

a#b = abs$a-b

main = B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:h1:h2:hv)=snd $ fst $ foldl' proc ((0,h1#h2),take n (h1:h2:hv)) [3..n]
proc ((u1,u2),h1:h2:h3:hv) _ = ((u2, min (u1+h1#h3) (u2+h2#h3)), h2:h3:hv)
