import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int coin500 = x / 500;
    int remain = x - coin500 * 500;
    System.out.println(coin500 * 1000 + (remain / 5) * 5);
    }
      
      
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int coin500 = x / 500;
    int remain = x - coin500 * 500;
    System.out.println(coin500 * 1000 + (remain / 5) * 5);
    }
      
      
} Main public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int coin500 = x / 500;
    int remain = x - coin500 * 500;
    System.out.println(coin500 * 1000 + (remain / 5) * 5);
    } main {
	Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int coin500 = x / 500;
    int remain = x - coin500 * 500;
    System.out.println(coin500 * 1000 + (remain / 5) * 5);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = Integer.parseInt(sc.next()); x Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int coin500 = x / 500; coin500 x / 500 x 500 int remain = x - coin500 * 500; remain x - coin500 * 500 x coin500 * 500 coin500 500 System.out.println(coin500 * 1000 + (remain / 5) * 5) System.out.println System.out System System.out coin500 * 1000 + (remain / 5) * 5 coin500 * 1000 coin500 1000 (remain / 5) * 5 (remain / 5) remain 5 5 String[] args args public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int coin500 = x / 500;
    int remain = x - coin500 * 500;
    System.out.println(coin500 * 1000 + (remain / 5) * 5);
    }
      
      
} public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int coin500 = x / 500;
    int remain = x - coin500 * 500;
    System.out.println(coin500 * 1000 + (remain / 5) * 5);
    }
      
      
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int x = Integer.parseInt(sc.next());
    int coin500 = x / 500;
    int remain = x - coin500 * 500;
    System.out.println(coin500 * 1000 + (remain / 5) * 5);
    }
      
      
}