import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
      
        int most = X / 500;
        int least = (X-most*500)/5;
      
        int ans = most*1000 + least*5;
        System.out.println(ans);
	}

} import java.util.*; util.* java public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
      
        int most = X / 500;
        int least = (X-most*500)/5;
      
        int ans = most*1000 + least*5;
        System.out.println(ans);
	}

} Main public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
      
        int most = X / 500;
        int least = (X-most*500)/5;
      
        int ans = most*1000 + least*5;
        System.out.println(ans);
	} main {

		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
      
        int most = X / 500;
        int least = (X-most*500)/5;
      
        int ans = most*1000 + least*5;
        System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int most = X / 500; most X / 500 X 500 int least = (X-most*500)/5; least (X-most*500)/5 (X-most*500) X most*500 most 500 5 int ans = most*1000 + least*5; ans most*1000 + least*5 most*1000 most 1000 least*5 least 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
      
        int most = X / 500;
        int least = (X-most*500)/5;
      
        int ans = most*1000 + least*5;
        System.out.println(ans);
	}

} public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
      
        int most = X / 500;
        int least = (X-most*500)/5;
      
        int ans = most*1000 + least*5;
        System.out.println(ans);
	}

} Main
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
      
        int most = X / 500;
        int least = (X-most*500)/5;
      
        int ans = most*1000 + least*5;
        System.out.println(ans);
	}

}