import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int m = x/500;
		int n = x%500;
		
		int l = n/5;
		
		System.out.println((m*1000)+(l*5));

	}

} 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 m = x/500;
		int n = x%500;
		
		int l = n/5;
		
		System.out.println((m*1000)+(l*5));

	}

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

	} main {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int m = x/500;
		int n = x%500;
		
		int l = n/5;
		
		System.out.println((m*1000)+(l*5));

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int m = x/500; m x/500 x 500 int n = x%500; n x%500 x 500 int l = n/5; l n/5 n 5 System.out.println((m*1000)+(l*5)) System.out.println System.out System System.out (m*1000)+(l*5) (m*1000) m 1000 (l*5) l 5 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int m = x/500;
		int n = x%500;
		
		int l = n/5;
		
		System.out.println((m*1000)+(l*5));

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int m = x/500;
		int n = x%500;
		
		int l = n/5;
		
		System.out.println((m*1000)+(l*5));

	}

} 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 m = x/500;
		int n = x%500;
		
		int l = n/5;
		
		System.out.println((m*1000)+(l*5));

	}

}
