import qualified Data.ByteString.Char8 as B

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

solve :: Int -> Int
solve x = q1 * 1000 + q2 * 5
  where
    (q1, r1) = x `divMod` 500
    q2 = r1 `div` 5
