import java.util.*;

class Main {
	Scanner sc;
	int X;
	
	void calc() {
		sc = new Scanner(System.in);
		X = sc.nextInt();
		System.out.println( (X/500)*1000 + (X%500)/5*5 );
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
} import java.util.*; util.* java class Main {
	Scanner sc;
	int X;
	
	void calc() {
		sc = new Scanner(System.in);
		X = sc.nextInt();
		System.out.println( (X/500)*1000 + (X%500)/5*5 );
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
} Main Scanner sc; sc int X; X void calc() {
		sc = new Scanner(System.in);
		X = sc.nextInt();
		System.out.println( (X/500)*1000 + (X%500)/5*5 );
	} calc {
		sc = new Scanner(System.in);
		X = sc.nextInt();
		System.out.println( (X/500)*1000 + (X%500)/5*5 );
	} sc = new Scanner(System.in) sc new Scanner(System.in) X = sc.nextInt() X sc.nextInt() sc.nextInt sc System.out.println( (X/500)*1000 + (X%500)/5*5 ) System.out.println System.out System System.out (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 public static void main(String[] args) {
		new Main().calc();
	} main {
		new Main().calc();
	} new Main().calc() new Main().calc new Main() String[] args args
import java.util.*;

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