import java.util.*;


class Main{
public static void main(String[] args) {
  Scanner reader=new Scanner(System.in);
  int x=reader.nextInt();
  int sum=x;
  int happy=0;
  happy=sum/500*1000;
    sum=sum-sum/500*500;
    happy+=sum/5*5;
    System.out.println(happy);


}
} import java.util.*; util.* java class Main{
public static void main(String[] args) {
  Scanner reader=new Scanner(System.in);
  int x=reader.nextInt();
  int sum=x;
  int happy=0;
  happy=sum/500*1000;
    sum=sum-sum/500*500;
    happy+=sum/5*5;
    System.out.println(happy);


}
} Main public static void main(String[] args) {
  Scanner reader=new Scanner(System.in);
  int x=reader.nextInt();
  int sum=x;
  int happy=0;
  happy=sum/500*1000;
    sum=sum-sum/500*500;
    happy+=sum/5*5;
    System.out.println(happy);


} main {
  Scanner reader=new Scanner(System.in);
  int x=reader.nextInt();
  int sum=x;
  int happy=0;
  happy=sum/500*1000;
    sum=sum-sum/500*500;
    happy+=sum/5*5;
    System.out.println(happy);


} Scanner reader=new Scanner(System.in); reader new Scanner(System.in) int x=reader.nextInt(); x reader.nextInt() reader.nextInt reader int sum=x; sum x int happy=0; happy 0 happy=sum/500*1000 happy sum/500*1000 sum/500 sum 500 1000 sum=sum-sum/500*500 sum sum-sum/500*500 sum sum/500*500 sum/500 sum 500 500 happy+=sum/5*5 happy sum/5*5 sum/5 sum 5 5 System.out.println(happy) System.out.println System.out System System.out happy String[] args args
import java.util.*;


class Main{
public static void main(String[] args) {
  Scanner reader=new Scanner(System.in);
  int x=reader.nextInt();
  int sum=x;
  int happy=0;
  happy=sum/500*1000;
    sum=sum-sum/500*500;
    happy+=sum/5*5;
    System.out.println(happy);


}
}