import Data.List (tails)

main :: IO ()
main = readLn >>= print . solve

solve :: Int -> Int
solve = minimum . diff753s

diff753s :: Int -> [Int]
diff753s = map (diff753 . read) . slices 3 . show

diff753 :: Int -> Int
diff753 = abs . subtract 753

slices :: Int -> [a] -> [[a]]
slices n xs = [take n t | t <- tails xs, length t >= n]
