import Foundation

var x = Int(readLine()!) ?? 0
var money = [0,0]
 
money[0] = (x / 500) * 1000
x = x % 500 
money[1] = (x / 5) * 5
x = x % 5
 
let happinessScore =  money.reduce(0) { (num1: Int, num2: Int) -> Int in
  return num1 + num2
}

print(happinessScore)
