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:hr)=s 0 (h2#h1) (take n (h1:h2:hr))
s _ c [_,_] = c
s c1 c2 (h1:h2:h3:hr)=s c2 (min (c1+h3#h1) (c2+h3#h2)) (h2:h3:hr)
