import java.io.*;

class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		}
	}
} import java.io.*; io.* java class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		}
	}
} Main public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		}
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		}
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) try{
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} IOException e {
			System.out.println(e);
			System.exit(0);
		} System.out.println(e) System.out.println System.out System System.out e System.exit(0) System.exit System 0 catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		} NumberFormatException e {
			System.out.println(e);
			System.exit(0);
		} System.out.println(e) System.out.println System.out System System.out e System.exit(0) System.exit System 0 {
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} String line = reader.readLine(); line reader.readLine() reader.readLine reader int money = Integer.parseInt(line); money Integer.parseInt(line) Integer.parseInt Integer line int fiveHundreds = money/500; fiveHundreds money/500 money 500 int five = (money%500)/5; five (money%500)/5 (money%500) money 500 5 int happy = 1000*fiveHundreds + 5*five; happy 1000*fiveHundreds + 5*five 1000*fiveHundreds 1000 fiveHundreds 5*five 5 five System.out.println(happy) System.out.println System.out System System.out happy String[] args args
import java.io.*;

class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try{
			String line = reader.readLine();
			int money = Integer.parseInt(line);

			int fiveHundreds = money/500;
			int five = (money%500)/5;

			int happy = 1000*fiveHundreds + 5*five;

			System.out.println(happy);

		} catch (IOException e){
			System.out.println(e);
			System.exit(0);
		} catch (NumberFormatException e){
			System.out.println(e);
			System.exit(0);
		}
	}
}