import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main {
    public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 int s = sc.nextInt();
		 int total = 0;
		 total += s/500 * 1000;
		 s %= 500;
		 total += s/5 *5;
		 System.out.println(total);
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main {
    public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 int s = sc.nextInt();
		 int total = 0;
		 total += s/500 * 1000;
		 s %= 500;
		 total += s/5 *5;
		 System.out.println(total);
	}
} Main public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 int s = sc.nextInt();
		 int total = 0;
		 total += s/500 * 1000;
		 s %= 500;
		 total += s/5 *5;
		 System.out.println(total);
	} main {
		 Scanner sc = new Scanner(System.in);
		 int s = sc.nextInt();
		 int total = 0;
		 total += s/500 * 1000;
		 s %= 500;
		 total += s/5 *5;
		 System.out.println(total);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int s = sc.nextInt(); s sc.nextInt() sc.nextInt sc int total = 0; total 0 total += s/500 * 1000 total s/500 * 1000 s/500 s 500 1000 s %= 500 s 500 total += s/5 *5 total s/5 *5 s/5 s 5 5 System.out.println(total) System.out.println System.out System System.out total String args[] args public class Main {
    public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 int s = sc.nextInt();
		 int total = 0;
		 total += s/500 * 1000;
		 s %= 500;
		 total += s/5 *5;
		 System.out.println(total);
	}
} public class Main {
    public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 int s = sc.nextInt();
		 int total = 0;
		 total += s/500 * 1000;
		 s %= 500;
		 total += s/5 *5;
		 System.out.println(total);
	}
} Main
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main {
    public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 int s = sc.nextInt();
		 int total = 0;
		 total += s/500 * 1000;
		 s %= 500;
		 total += s/5 *5;
		 System.out.println(total);
	}
}