import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	}

} import java.util.Scanner; Scanner java.util public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	}

} Main private static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static void p(String ans) {System.out.println(ans);} p {System.out.println(ans);} System.out.println(ans) System.out.println System.out System System.out ans String ans ans static void p(int ans) {System.out.println(ans);} p {System.out.println(ans);} System.out.println(ans) System.out.println System.out System System.out ans int ans ans static void p(long ans) {System.out.println(ans);} p {System.out.println(ans);} System.out.println(ans) System.out.println System.out System System.out ans long ans ans public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	} main {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	} int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int ans = x/500*1000+x%500/5*5; ans x/500*1000+x%500/5*5 x/500*1000 x/500 x 500 1000 x%500/5*5 x%500/5 x%500 x 500 5 5 p(ans) p ans String[] args args public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	}

} public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	}

} Main
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int x = sc.nextInt();
		int ans = x/500*1000+x%500/5*5;
		p(ans);
		
	}

}
