//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a,b;
		if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		}
		if(X<500) {
			b = X/5*5;
			System.out.println(b);
		}
	}
} import java.util.*; util.* java public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a,b;
		if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		}
		if(X<500) {
			b = X/5*5;
			System.out.println(b);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a,b;
		if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		}
		if(X<500) {
			b = X/5*5;
			System.out.println(b);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a,b;
		if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		}
		if(X<500) {
			b = X/5*5;
			System.out.println(b);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int a a b; b if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		} X>=500 X 500 {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		} a = 1000*(X/500) a 1000*(X/500) 1000 (X/500) X 500 b = X%500/5*5 b X%500/5*5 X%500/5 X%500 X 500 5 5 System.out.println(a+b) System.out.println System.out System System.out a+b a b if(X<500) {
			b = X/5*5;
			System.out.println(b);
		} X<500 X 500 {
			b = X/5*5;
			System.out.println(b);
		} b = X/5*5 b X/5*5 X/5 X 5 5 System.out.println(b) System.out.println System.out System System.out b String[] args args public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a,b;
		if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		}
		if(X<500) {
			b = X/5*5;
			System.out.println(b);
		}
	}
} public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a,b;
		if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		}
		if(X<500) {
			b = X/5*5;
			System.out.println(b);
		}
	}
} Main
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a,b;
		if(X>=500) {
			a = 1000*(X/500);
			//System.out.println(a);
			b = X%500/5*5;
			//System.out.println(b);
			System.out.println(a+b);
		}
		if(X<500) {
			b = X/5*5;
			System.out.println(b);
		}
	}
}