import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  x <- getInt
  let n500 = x `div` 500
      n5 = (x - 500 * n500) `div` 5
      ans = 1000 * n500 + 5 * n5
  print ans