main :: IO ()
main = do
  n <- readLn
  print $ solve n

solve :: Int -> Int
solve n = minimum cs
  where
    cs = map (\x -> abs (x - 753))
      $ filter (>110) [ n `div` m `mod` 1000 | m <- (map (10^) [0..10]) ]
