import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	}
} Main public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	} main {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	} Scanner in=new Scanner (System.in); in new Scanner (System.in) int x=in.nextInt(); x in.nextInt() in.nextInt in int m1= (x/500)*1000; m1 (x/500)*1000 (x/500) x 500 1000 int r= x-(m1/2); r x-(m1/2) x (m1/2) m1 2 int m2=(r/5)*5; m2 (r/5)*5 (r/5) r 5 5 System.out.println(m1+m2) System.out.println System.out System System.out m1+m2 m1 m2 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int x=in.nextInt();
		int m1= (x/500)*1000;
		int r= x-(m1/2);
		int m2=(r/5)*5;
		System.out.println(m1+m2);
	}
}