main :: IO ()
main = do
    n <- readLn
    putStrLn . show $ getMax n

getMax :: Int -> Int
getMax n =
    let
        m500 = n `div` 500
        m5 = (n - m500 * 500) `div` 5
    in
    m500 * 1000 + m5 * 5
