import java.util.Scanner;

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

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