import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = a%500;
    long c = (long) (a-b)/500;
    long d = b%5;
    long e = (long) (b-d)/5;
    System.out.println(e*5+c*1000);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = a%500;
    long c = (long) (a-b)/500;
    long d = b%5;
    long e = (long) (b-d)/5;
    System.out.println(e*5+c*1000);
  }
} Main public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = a%500;
    long c = (long) (a-b)/500;
    long d = b%5;
    long e = (long) (b-d)/5;
    System.out.println(e*5+c*1000);
  } main {
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = a%500;
    long c = (long) (a-b)/500;
    long d = b%5;
    long e = (long) (b-d)/5;
    System.out.println(e*5+c*1000);
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a = scan.nextLong(); a scan.nextLong() scan.nextLong scan long b = a%500; b a%500 a 500 long c = (long) (a-b)/500; c (long) (a-b)/500 (long) (a-b) a b 500 long d = b%5; d b%5 b 5 long e = (long) (b-d)/5; e (long) (b-d)/5 (long) (b-d) b d 5 System.out.println(e*5+c*1000) System.out.println System.out System System.out e*5+c*1000 e*5 e 5 c*1000 c 1000 String[] args args public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = a%500;
    long c = (long) (a-b)/500;
    long d = b%5;
    long e = (long) (b-d)/5;
    System.out.println(e*5+c*1000);
  }
} public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = a%500;
    long c = (long) (a-b)/500;
    long d = b%5;
    long e = (long) (b-d)/5;
    System.out.println(e*5+c*1000);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    long b = a%500;
    long c = (long) (a-b)/500;
    long d = b%5;
    long e = (long) (b-d)/5;
    System.out.println(e*5+c*1000);
  }
}
