import java.util._

object Main {
  def main(args: Array[String]) = {
    val scanner = new Scanner(System.in)
    val money = scanner.nextLong
    val fiveHundredCoins = money / 500;
    val fiveCoins = (money % 500) / 5
    println(fiveHundredCoins * 1000 + fiveCoins * 5)
  }
}
