import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	} main {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc sc.close() sc.close sc int s500 = X/500; s500 X/500 X 500 int s5 = (X%500)/5; s5 (X%500)/5 (X%500) X 500 5 int uresi = s500*1000 + s5*5; uresi s500*1000 + s5*5 s500*1000 s500 1000 s5*5 s5 5 System.out.println(uresi) System.out.println System.out System System.out uresi String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	}

}