import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();
		int ans = (x/500)*1000 + (x%500)/5*5;
		System.out.println(ans);

	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();
		int ans = (x/500)*1000 + (x%500)/5*5;
		System.out.println(ans);

	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();
		int ans = (x/500)*1000 + (x%500)/5*5;
		System.out.println(ans);

	} main {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();
		int ans = (x/500)*1000 + (x%500)/5*5;
		System.out.println(ans);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan scan.close() scan.close scan 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 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();
		int ans = (x/500)*1000 + (x%500)/5*5;
		System.out.println(ans);

	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();
		int ans = (x/500)*1000 + (x%500)/5*5;
		System.out.println(ans);

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();
		int ans = (x/500)*1000 + (x%500)/5*5;
		System.out.println(ans);

	}
}