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