import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int happiness = 0;
		int x = kb.nextInt();
		while (x>=500) {
			happiness+=1000;
			x-=500;
		}
		while(x>=5) {
			happiness+=5;
			x-=5;
		}
		System.out.println(happiness);
		kb.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int happiness = 0;
		int x = kb.nextInt();
		while (x>=500) {
			happiness+=1000;
			x-=500;
		}
		while(x>=5) {
			happiness+=5;
			x-=5;
		}
		System.out.println(happiness);
		kb.close();
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int happiness = 0;
		int x = kb.nextInt();
		while (x>=500) {
			happiness+=1000;
			x-=500;
		}
		while(x>=5) {
			happiness+=5;
			x-=5;
		}
		System.out.println(happiness);
		kb.close();
	} main {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int happiness = 0;
		int x = kb.nextInt();
		while (x>=500) {
			happiness+=1000;
			x-=500;
		}
		while(x>=5) {
			happiness+=5;
			x-=5;
		}
		System.out.println(happiness);
		kb.close();
	} Scanner kb = new Scanner(System.in); kb new Scanner(System.in) int happiness = 0; happiness 0 int x = kb.nextInt(); x kb.nextInt() kb.nextInt kb while (x>=500) {
			happiness+=1000;
			x-=500;
		} x>=500 x 500 {
			happiness+=1000;
			x-=500;
		} happiness+=1000 happiness 1000 x-=500 x 500 while(x>=5) {
			happiness+=5;
			x-=5;
		} x>=5 x 5 {
			happiness+=5;
			x-=5;
		} happiness+=5 happiness 5 x-=5 x 5 System.out.println(happiness) System.out.println System.out System System.out happiness kb.close() kb.close kb String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int happiness = 0;
		int x = kb.nextInt();
		while (x>=500) {
			happiness+=1000;
			x-=500;
		}
		while(x>=5) {
			happiness+=5;
			x-=5;
		}
		System.out.println(happiness);
		kb.close();
	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int happiness = 0;
		int x = kb.nextInt();
		while (x>=500) {
			happiness+=1000;
			x-=500;
		}
		while(x>=5) {
			happiness+=5;
			x-=5;
		}
		System.out.println(happiness);
		kb.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int happiness = 0;
		int x = kb.nextInt();
		while (x>=500) {
			happiness+=1000;
			x-=500;
		}
		while(x>=5) {
			happiness+=5;
			x-=5;
		}
		System.out.println(happiness);
		kb.close();
	}

}
