import java.util.Scanner


import scala.io.StdIn._

object Main extends App {

  val x = readInt()

  def solve() = {
    val cnt500coin = x/500
    cnt500coin *1000 + (x - cnt500coin *500)/5 *5
  }

  println(solve())

}

