import java.util.*;
import java.math.*;

class Main{
public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   long x = sc.nextInt();
   long ret = 1000*(x/500);
   x %= 500;
   ret += 5*(x/5);
   System.out.println(ret); 
}
} import java.util.*; util.* java import java.math.*; math.* java class Main{
public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   long x = sc.nextInt();
   long ret = 1000*(x/500);
   x %= 500;
   ret += 5*(x/5);
   System.out.println(ret); 
}
} Main public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   long x = sc.nextInt();
   long ret = 1000*(x/500);
   x %= 500;
   ret += 5*(x/5);
   System.out.println(ret); 
} main {
   Scanner sc = new Scanner(System.in);
   long x = sc.nextInt();
   long ret = 1000*(x/500);
   x %= 500;
   ret += 5*(x/5);
   System.out.println(ret); 
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long x = sc.nextInt(); x sc.nextInt() sc.nextInt sc long ret = 1000*(x/500); ret 1000*(x/500) 1000 (x/500) x 500 x %= 500 x 500 ret += 5*(x/5) ret 5*(x/5) 5 (x/5) x 5 System.out.println(ret) System.out.println System.out System System.out ret String args[] args
import java.util.*;
import java.math.*;

class Main{
public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   long x = sc.nextInt();
   long ret = 1000*(x/500);
   x %= 500;
   ret += 5*(x/5);
   System.out.println(ret); 
}
}
