import Foundation
var X = Int(readLine()!) ?? 0
var moneyArray = [0,0]

moneyArray[0] = (X/500)*1000
X = X%500 
moneyArray[1] = (X/5)*5
X = X%5

let happiness =  moneyArray.reduce(0){(num1: Int, num2: Int)  -> Int in
  return num1 + num2
}
print(happiness)