main = do
    putStrLn . show . solve =<< getLine

-- |
-- >>> solve "1234567876"
-- 34
-- >>> solve "35753"
-- 0
-- >>> solve "1111111111"
-- 642

solve :: String -> Int
solve = solve' 753 753
  where
    solve' u m s = case s of
        a:s'@(b:c:_)
            | n < m     -> solve' u n s'
            | otherwise -> solve' u m s'
          where
            n = abs $ u - read (a:b:c:[])
        _ -> m
