import java.util.Scanner;

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

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