{-# LANGUAGE BangPatterns, FlexibleContexts #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Array
import Data.Array.ST
import Data.List
import Debug.Trace (traceShow, traceShowM)
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

solve :: String -> Int
solve xs = minimum $ fmap (\z -> abs $ z - 753) $ do
    ys <- tails xs
    guard (length ys >= 3)
    let z = read $ take 3 ys :: Int
    return z

main :: IO ()
main = do
    xs <- getLine
    print $ solve xs