import java.util.*;
public class Main{
  
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N=scanner.nextInt();
    int remDiv=((N%500)/5);

    int gc=((N/500)*1000)+(remDiv*5);
    System.out.println(gc);
  }

} import java.util.*; util.* java public class Main{
  
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N=scanner.nextInt();
    int remDiv=((N%500)/5);

    int gc=((N/500)*1000)+(remDiv*5);
    System.out.println(gc);
  }

} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N=scanner.nextInt();
    int remDiv=((N%500)/5);

    int gc=((N/500)*1000)+(remDiv*5);
    System.out.println(gc);
  } main {
    Scanner scanner = new Scanner(System.in);
    int N=scanner.nextInt();
    int remDiv=((N%500)/5);

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

    int gc=((N/500)*1000)+(remDiv*5);
    System.out.println(gc);
  }

} public class Main{
  
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N=scanner.nextInt();
    int remDiv=((N%500)/5);

    int gc=((N/500)*1000)+(remDiv*5);
    System.out.println(gc);
  }

} Main
import java.util.*;
public class Main{
  
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N=scanner.nextInt();
    int remDiv=((N%500)/5);

    int gc=((N/500)*1000)+(remDiv*5);
    System.out.println(gc);
  }

}