import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int fiveHundred = 0, five = 0, one = 0;
		while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		}

		System.out.println(1000 * fiveHundred + 5 * five);
	}
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int fiveHundred = 0, five = 0, one = 0;
		while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		}

		System.out.println(1000 * fiveHundred + 5 * five);
	}
} Main public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int fiveHundred = 0, five = 0, one = 0;
		while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		}

		System.out.println(1000 * fiveHundred + 5 * five);
	} main {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int fiveHundred = 0, five = 0, one = 0;
		while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		}

		System.out.println(1000 * fiveHundred + 5 * five);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc sc.close() sc.close sc int fiveHundred = 0 fiveHundred 0 five = 0 five 0 one = 0; one 0 while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		} x!=0 x 0 {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		} if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			} x%500 == 0 x%500 x 500 0 {
				x-=500; fiveHundred++;
			} x-=500 x 500 fiveHundred++ fiveHundred if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			} x%5 == 0 x%5 x 5 0 {
				x-=5; five++;
			} x-=5 x 5 five++ five {
				x-=1; one++;
			} x-=1 x 1 one++ one System.out.println(1000 * fiveHundred + 5 * five) System.out.println System.out System System.out 1000 * fiveHundred + 5 * five 1000 * fiveHundred 1000 fiveHundred 5 * five 5 five String[] args args public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int fiveHundred = 0, five = 0, one = 0;
		while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		}

		System.out.println(1000 * fiveHundred + 5 * five);
	}
} public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int fiveHundred = 0, five = 0, one = 0;
		while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		}

		System.out.println(1000 * fiveHundred + 5 * five);
	}
} Main
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int fiveHundred = 0, five = 0, one = 0;
		while (x!=0) {
			if (x%500 == 0) {
				x-=500; fiveHundred++;
			} else if (x%5 == 0) {
				x-=5; five++;
			} else {
				x-=1; one++;
			}
		}

		System.out.println(1000 * fiveHundred + 5 * five);
	}
}
