object Main extends App {
  var input = readLine.toInt
  var sum = 0
  
  if(input >= 500) {
    var tempo = (input / 500).toInt
    sum = sum + tempo * 1000
    input = input - tempo * 500
  }
  
  sum = sum + (input / 5).toInt * 5
  
  println(sum)
  
}