{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import qualified Data.Sequence as SQ
import Data.Sequence ((|>), ViewL(..))

main=do
    x<-readLn :: IO Int
    print $ f x $ SQ.singleton (0,0)

f x (SQ.viewl -> (a,i) :< seq)
    | x == a = i
    | True = f x $ n seq (i+1) [a-(i+1), a, a+i+1]

n seq i [] = seq
n seq i (a:as)= n (seq|>(a,i)) i as