import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		int y500 = y/500;
		y =y - y500*500;
		int y5 = y/5;
		System.out.println(y500*1000+y5*5);
		
		
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		int y500 = y/500;
		y =y - y500*500;
		int y5 = y/5;
		System.out.println(y500*1000+y5*5);
		
		
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		int y500 = y/500;
		y =y - y500*500;
		int y5 = y/5;
		System.out.println(y500*1000+y5*5);
		
		
	} main {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		int y500 = y/500;
		y =y - y500*500;
		int y5 = y/5;
		System.out.println(y500*1000+y5*5);
		
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int y = sc.nextInt(); y sc.nextInt() sc.nextInt sc int y500 = y/500; y500 y/500 y 500 y =y - y500*500 y y - y500*500 y y500*500 y500 500 int y5 = y/5; y5 y/5 y 5 System.out.println(y500*1000+y5*5) System.out.println System.out System System.out y500*1000+y5*5 y500*1000 y500 1000 y5*5 y5 5 String args[] args public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		int y500 = y/500;
		y =y - y500*500;
		int y5 = y/5;
		System.out.println(y500*1000+y5*5);
		
		
	}
} public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		int y500 = y/500;
		y =y - y500*500;
		int y5 = y/5;
		System.out.println(y500*1000+y5*5);
		
		
	}
} Main
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int y = sc.nextInt();
		int y500 = y/500;
		y =y - y500*500;
		int y5 = y/5;
		System.out.println(y500*1000+y5*5);
		
		
	}
}
