import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long x = scan.nextLong();
		long count500 = 0;
		long count5 = 0;
		
		
		if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		}
		if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		}
		/*
		System.out.println(count500);
		System.out.println(count5);
		System.out.println(x);
		*/
		
		long ans = 1000 * count500 + 5 * count5;
		
		System.out.println(ans);
	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long x = scan.nextLong();
		long count500 = 0;
		long count5 = 0;
		
		
		if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		}
		if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		}
		/*
		System.out.println(count500);
		System.out.println(count5);
		System.out.println(x);
		*/
		
		long ans = 1000 * count500 + 5 * count5;
		
		System.out.println(ans);
	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long x = scan.nextLong();
		long count500 = 0;
		long count5 = 0;
		
		
		if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		}
		if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		}
		/*
		System.out.println(count500);
		System.out.println(count5);
		System.out.println(x);
		*/
		
		long ans = 1000 * count500 + 5 * count5;
		
		System.out.println(ans);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long x = scan.nextLong();
		long count500 = 0;
		long count5 = 0;
		
		
		if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		}
		if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		}
		/*
		System.out.println(count500);
		System.out.println(count5);
		System.out.println(x);
		*/
		
		long ans = 1000 * count500 + 5 * count5;
		
		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long x = scan.nextLong(); x scan.nextLong() scan.nextLong scan long count500 = 0; count500 0 long count5 = 0; count5 0 if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		} x % 500 >= 0 x % 500 x 500 0 {
			count500 = (x - x % 500) / 500;
			x %= 500;
		} count500 = (x - x % 500) / 500 count500 (x - x % 500) / 500 (x - x % 500) x x % 500 x 500 500 x %= 500 x 500 if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		} x % 5 >= 0 x % 5 x 5 0 {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		} count5 = (x - x % 5) / 5 count5 (x - x % 5) / 5 (x - x % 5) x x % 5 x 5 5 x %= 5 x 5 long ans = 1000 * count500 + 5 * count5; ans 1000 * count500 + 5 * count5 1000 * count500 1000 count500 5 * count5 5 count5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long x = scan.nextLong();
		long count500 = 0;
		long count5 = 0;
		
		
		if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		}
		if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		}
		/*
		System.out.println(count500);
		System.out.println(count5);
		System.out.println(x);
		*/
		
		long ans = 1000 * count500 + 5 * count5;
		
		System.out.println(ans);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long x = scan.nextLong();
		long count500 = 0;
		long count5 = 0;
		
		
		if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		}
		if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		}
		/*
		System.out.println(count500);
		System.out.println(count5);
		System.out.println(x);
		*/
		
		long ans = 1000 * count500 + 5 * count5;
		
		System.out.println(ans);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long x = scan.nextLong();
		long count500 = 0;
		long count5 = 0;
		
		
		if(x % 500 >= 0) {
			count500 = (x - x % 500) / 500;
			x %= 500;
		}
		if(x % 5 >= 0) {
			count5 = (x - x % 5) / 5;
			x %= 5;
			
		}
		/*
		System.out.println(count500);
		System.out.println(count5);
		System.out.println(x);
		*/
		
		long ans = 1000 * count500 + 5 * count5;
		
		System.out.println(ans);
	}

}
