import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int total =0;
		int fivehund = x/500;
		total = fivehund * 1000;
		int a = x - (fivehund * 500);
		int fives = a / 5;
		total+= fives*5;
		System.out.println(total);
	}
	
} 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 total =0;
		int fivehund = x/500;
		total = fivehund * 1000;
		int a = x - (fivehund * 500);
		int fives = a / 5;
		total+= fives*5;
		System.out.println(total);
	}
	
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int total =0;
		int fivehund = x/500;
		total = fivehund * 1000;
		int a = x - (fivehund * 500);
		int fives = a / 5;
		total+= fives*5;
		System.out.println(total);
	} main {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int total =0;
		int fivehund = x/500;
		total = fivehund * 1000;
		int a = x - (fivehund * 500);
		int fives = a / 5;
		total+= fives*5;
		System.out.println(total);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int x = in.nextInt(); x in.nextInt() in.nextInt in int total =0; total 0 int fivehund = x/500; fivehund x/500 x 500 total = fivehund * 1000 total fivehund * 1000 fivehund 1000 int a = x - (fivehund * 500); a x - (fivehund * 500) x (fivehund * 500) fivehund 500 int fives = a / 5; fives a / 5 a 5 total+= fives*5 total fives*5 fives 5 System.out.println(total) System.out.println System.out System System.out total String[] args args public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int total =0;
		int fivehund = x/500;
		total = fivehund * 1000;
		int a = x - (fivehund * 500);
		int fives = a / 5;
		total+= fives*5;
		System.out.println(total);
	}
	
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int total =0;
		int fivehund = x/500;
		total = fivehund * 1000;
		int a = x - (fivehund * 500);
		int fives = a / 5;
		total+= fives*5;
		System.out.println(total);
	}
	
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int total =0;
		int fivehund = x/500;
		total = fivehund * 1000;
		int a = x - (fivehund * 500);
		int fives = a / 5;
		total+= fives*5;
		System.out.println(total);
	}
	
}