import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = 0, b = 0, c = 0;
		a = x / 500; b = (x - a * 500) / 5; c = ( a * 1000 + b * 5);
		System.out.println(c);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = 0, b = 0, c = 0;
		a = x / 500; b = (x - a * 500) / 5; c = ( a * 1000 + b * 5);
		System.out.println(c);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = 0, b = 0, c = 0;
		a = x / 500; b = (x - a * 500) / 5; c = ( a * 1000 + b * 5);
		System.out.println(c);
	} main {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = 0, b = 0, c = 0;
		a = x / 500; b = (x - a * 500) / 5; c = ( a * 1000 + b * 5);
		System.out.println(c);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long x = sc.nextLong(); x sc.nextLong() sc.nextLong sc long a = 0 a 0 b = 0 b 0 c = 0; c 0 a = x / 500 a x / 500 x 500 b = (x - a * 500) / 5 b (x - a * 500) / 5 (x - a * 500) x a * 500 a 500 5 c = ( a * 1000 + b * 5) c ( a * 1000 + b * 5) a * 1000 a 1000 b * 5 b 5 System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = 0, b = 0, c = 0;
		a = x / 500; b = (x - a * 500) / 5; c = ( a * 1000 + b * 5);
		System.out.println(c);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = 0, b = 0, c = 0;
		a = x / 500; b = (x - a * 500) / 5; c = ( a * 1000 + b * 5);
		System.out.println(c);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long a = 0, b = 0, c = 0;
		a = x / 500; b = (x - a * 500) / 5; c = ( a * 1000 + b * 5);
		System.out.println(c);
	}
}
