import Data.Char

scan :: [Int] -> Int
scan  = iter 999 where
    iter m [_, _] = m
    iter m (x:y:z:xs) = iter (min (abs (100*x+10*y+z-753)) m) (y:z:xs)  

main :: IO() 
main = do
    s <- getLine
    let ans = scan (map (\x -> digitToInt x) s)
    print ans