
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = Integer.parseInt(sc.next());

		int ure = 0;

		while(X >= 500) {
			ure += (X / 500)*1000;
			X %= 500;

		}

		while(X >= 5) {
			ure += (X / 5)*5;
			X %= 5;

		}



		System.out.println(ure);

	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = Integer.parseInt(sc.next());

		int ure = 0;

		while(X >= 500) {
			ure += (X / 500)*1000;
			X %= 500;

		}

		while(X >= 5) {
			ure += (X / 5)*5;
			X %= 5;

		}



		System.out.println(ure);

	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = Integer.parseInt(sc.next());

		int ure = 0;

		while(X >= 500) {
			ure += (X / 500)*1000;
			X %= 500;

		}

		while(X >= 5) {
			ure += (X / 5)*5;
			X %= 5;

		}



		System.out.println(ure);

	} main {

		Scanner sc = new Scanner(System.in);

		int X = Integer.parseInt(sc.next());

		int ure = 0;

		while(X >= 500) {
			ure += (X / 500)*1000;
			X %= 500;

		}

		while(X >= 5) {
			ure += (X / 5)*5;
			X %= 5;

		}



		System.out.println(ure);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = Integer.parseInt(sc.next()); X Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int ure = 0; ure 0 while(X >= 500) {
			ure += (X / 500)*1000;
			X %= 500;

		} X >= 500 X 500 {
			ure += (X / 500)*1000;
			X %= 500;

		} ure += (X / 500)*1000 ure (X / 500)*1000 (X / 500) X 500 1000 X %= 500 X 500 while(X >= 5) {
			ure += (X / 5)*5;
			X %= 5;

		} X >= 5 X 5 {
			ure += (X / 5)*5;
			X %= 5;

		} ure += (X / 5)*5 ure (X / 5)*5 (X / 5) X 5 5 X %= 5 X 5 System.out.println(ure) System.out.println System.out System System.out ure String[] args args

import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = Integer.parseInt(sc.next());

		int ure = 0;

		while(X >= 500) {
			ure += (X / 500)*1000;
			X %= 500;

		}

		while(X >= 5) {
			ure += (X / 5)*5;
			X %= 5;

		}



		System.out.println(ure);

	}
}