import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int x = Integer.parseInt(in.readLine());
		
		System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5));
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {

	public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int x = Integer.parseInt(in.readLine());
		
		System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5));
	}
} Main public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int x = Integer.parseInt(in.readLine());
		
		System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5));
	} main {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int x = Integer.parseInt(in.readLine());
		
		System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5));
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) int x = Integer.parseInt(in.readLine()); x Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5)) System.out.println System.out System System.out (long) 1000 * (x/500) + 5 * ((x%500)/5) (long) 1000 * (x/500) (long) 1000 (x/500) x 500 5 * ((x%500)/5) 5 ((x%500)/5) (x%500) x 500 5 String[] args args public class Main {

	public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int x = Integer.parseInt(in.readLine());
		
		System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5));
	}
} public class Main {

	public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int x = Integer.parseInt(in.readLine());
		
		System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5));
	}
} Main
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int x = Integer.parseInt(in.readLine());
		
		System.out.println((long) 1000 * (x/500) + 5 * ((x%500)/5));
	}
}
