import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      int X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      int X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    }
} Main public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      int X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    } main {
    
    Scanner sc = new Scanner(System.in);

      int X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X =sc.nextInt(); X sc.nextInt() sc.nextInt sc int Z = X/500; Z X/500 X 500 int B = Z*1000; B Z*1000 Z 1000 int A = (X-(500*Z))/5; A (X-(500*Z))/5 (X-(500*Z)) X (500*Z) 500 Z 5 int C = A*5; C A*5 A 5 System.out.print(B+C) System.out.print System.out System System.out B+C B C String[] args args public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      int X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    }
} public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      int X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);

      int X =sc.nextInt();
      
      int Z = X/500;
      int B = Z*1000;
      int A = (X-(500*Z))/5;
      int C = A*5;
      
      System.out.print(B+C);
    }
}
