/*package whatever //do not write package name here */

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

class Main {
	public static void main (String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int res=0;
	    res = res + 1000*(a/500);
	    a = a % 500;
	    res = res + 5*(a/5);
		System.out.println(res);
	}
} import java.io.*; io.* java import java.util.*; util.* java class Main {
	public static void main (String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int res=0;
	    res = res + 1000*(a/500);
	    a = a % 500;
	    res = res + 5*(a/5);
		System.out.println(res);
	}
} Main public static void main (String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int res=0;
	    res = res + 1000*(a/500);
	    a = a % 500;
	    res = res + 5*(a/5);
		System.out.println(res);
	} main {
	    Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int res=0;
	    res = res + 1000*(a/500);
	    a = a % 500;
	    res = res + 5*(a/5);
		System.out.println(res);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int res=0; res 0 res = res + 1000*(a/500) res res + 1000*(a/500) res 1000*(a/500) 1000 (a/500) a 500 a = a % 500 a a % 500 a 500 res = res + 5*(a/5) res res + 5*(a/5) res 5*(a/5) 5 (a/5) a 5 System.out.println(res) System.out.println System.out System System.out res String[] args args
/*package whatever //do not write package name here */

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

class Main {
	public static void main (String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int res=0;
	    res = res + 1000*(a/500);
	    a = a % 500;
	    res = res + 5*(a/5);
		System.out.println(res);
	}
}