import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int answer = 0;
		answer+=(N/500)*1000; N%=500;
		answer+=(N/5)*5;
		System.out.println(answer);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int answer = 0;
		answer+=(N/500)*1000; N%=500;
		answer+=(N/5)*5;
		System.out.println(answer);
	}
} Main public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int answer = 0;
		answer+=(N/500)*1000; N%=500;
		answer+=(N/5)*5;
		System.out.println(answer);
	} main {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int answer = 0;
		answer+=(N/500)*1000; N%=500;
		answer+=(N/5)*5;
		System.out.println(answer);
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int N = input.nextInt(); N input.nextInt() input.nextInt input int answer = 0; answer 0 answer+=(N/500)*1000 answer (N/500)*1000 (N/500) N 500 1000 N%=500 N 500 answer+=(N/5)*5 answer (N/5)*5 (N/5) N 5 5 System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int answer = 0;
		answer+=(N/500)*1000; N%=500;
		answer+=(N/5)*5;
		System.out.println(answer);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int answer = 0;
		answer+=(N/500)*1000; N%=500;
		answer+=(N/5)*5;
		System.out.println(answer);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int answer = 0;
		answer+=(N/500)*1000; N%=500;
		answer+=(N/5)*5;
		System.out.println(answer);
	}
}