import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    long X;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        X = sc.nextLong();
    }
    
    //解答処理
    private long solve() {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    }
    
    //出力
    public void show(long answer) {
        System.out.println(answer);
    }

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    long X;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        X = sc.nextLong();
    }
    
    //解答処理
    private long solve() {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    }
    
    //出力
    public void show(long answer) {
        System.out.println(answer);
    }

} Main //フィールド
    Scanner sc; sc long X; X public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Main m = new Main(sc); m new Main(sc) m.show(m.solve()) m.show m m.solve() m.solve m sc.close() sc.close sc String[] args args //入力
    Main(Scanner sc) {
        this.sc = sc;
        X = sc.nextLong();
    } Main {
        this.sc = sc;
        X = sc.nextLong();
    } this.sc = sc this.sc this this.sc sc X = sc.nextLong() X sc.nextLong() sc.nextLong sc Scanner sc sc //解答処理
    private long solve() {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    } solve {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    } long happy = 0; happy 0 while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         } X >= 500 X 500 {
        	 happy += 1000;
        	 X -= 500;
         } happy += 1000 happy 1000 X -= 500 X 500 while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         } X >= 5 X 5 {
        	 happy += 5;
        	 X -= 5;
         } happy += 5 happy 5 X -= 5 X 5 return happy; happy //出力
    public void show(long answer) {
        System.out.println(answer);
    } show {
        System.out.println(answer);
    } System.out.println(answer) System.out.println System.out System System.out answer long answer answer public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    long X;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        X = sc.nextLong();
    }
    
    //解答処理
    private long solve() {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    }
    
    //出力
    public void show(long answer) {
        System.out.println(answer);
    }

} public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    long X;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        X = sc.nextLong();
    }
    
    //解答処理
    private long solve() {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    }
    
    //出力
    public void show(long answer) {
        System.out.println(answer);
    }

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    long X;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        X = sc.nextLong();
    }
    
    //解答処理
    private long solve() {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    }
    
    //出力
    public void show(long answer) {
        System.out.println(answer);
    }

}
