import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int happy = 0;
		boolean b = false;
		
		if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		}
		if(X/5>=1) happy += X/5*5;
		
		System.out.print(happy);
	}
} 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 happy = 0;
		boolean b = false;
		
		if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		}
		if(X/5>=1) happy += X/5*5;
		
		System.out.print(happy);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int happy = 0;
		boolean b = false;
		
		if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		}
		if(X/5>=1) happy += X/5*5;
		
		System.out.print(happy);
	} main {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int happy = 0;
		boolean b = false;
		
		if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		}
		if(X/5>=1) happy += X/5*5;
		
		System.out.print(happy);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int happy = 0; happy 0 boolean b = false; b false if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		} X/500>=1 X/500 X 500 1 {
			happy = X/500*1000;
			X -= X/500*500;
		} happy = X/500*1000 happy X/500*1000 X/500 X 500 1000 X -= X/500*500 X X/500*500 X/500 X 500 500 if(X/5>=1) happy += X/5*5; X/5>=1 X/5 X 5 1 happy += X/5*5 happy X/5*5 X/5 X 5 5 System.out.print(happy) System.out.print System.out System System.out happy String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int happy = 0;
		boolean b = false;
		
		if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		}
		if(X/5>=1) happy += X/5*5;
		
		System.out.print(happy);
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int happy = 0;
		boolean b = false;
		
		if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		}
		if(X/5>=1) happy += X/5*5;
		
		System.out.print(happy);
	}
} 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 happy = 0;
		boolean b = false;
		
		if(X/500>=1){
			happy = X/500*1000;
			X -= X/500*500;
		}
		if(X/5>=1) happy += X/5*5;
		
		System.out.print(happy);
	}
}