import java.util.Scanner;

public class Main {

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

} 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();
		
		if (x < 5) {
			System.out.println(0);
			return;
		}
		
		int happy = (x / 500) * 1000;
		happy += ((x % 500) / 5) * 5;
		System.out.println(happy);
	}

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

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

} public class Main {

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

} Main
import java.util.Scanner;

public class Main {

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

}
