import java.util.Scanner;

public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		}
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz