import Control.Applicative

main :: IO ()
main = solve <$> getLine >>= print

solve :: String -> Int
solve = f 1000
  where
    f x s
      | l < 3 = x
      | otherwise = f (min x (abs (y - 753))) (tail s)
      where
        l = length s
        y = read . take 3 $ s
