import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    int X_500 = X / 500;
    if (X%500 > 0){
      int X_5 = (X - X_500*500)/5;
      System.out.println(X_500*1000+X_5*5);
    }
    else
      System.out.println(X_500*1000);
    
  }
} import java.util.*; util.* java class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    int X_500 = X / 500;
    if (X%500 > 0){
      int X_5 = (X - X_500*500)/5;
      System.out.println(X_500*1000+X_5*5);
    }
    else
      System.out.println(X_500*1000);
    
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    int X_500 = X / 500;
    if (X%500 > 0){
      int X_5 = (X - X_500*500)/5;
      System.out.println(X_500*1000+X_5*5);
    }
    else
      System.out.println(X_500*1000);
    
  } main {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    int X_500 = X / 500;
    if (X%500 > 0){
      int X_5 = (X - X_500*500)/5;
      System.out.println(X_500*1000+X_5*5);
    }
    else
      System.out.println(X_500*1000);
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int X_500 = X / 500; X_500 X / 500 X 500 if (X%500 > 0){
      int X_5 = (X - X_500*500)/5;
      System.out.println(X_500*1000+X_5*5);
    }
    else
      System.out.println(X_500*1000); X%500 > 0 X%500 X 500 0 {
      int X_5 = (X - X_500*500)/5;
      System.out.println(X_500*1000+X_5*5);
    } int X_5 = (X - X_500*500)/5; X_5 (X - X_500*500)/5 (X - X_500*500) X X_500*500 X_500 500 5 System.out.println(X_500*1000+X_5*5) System.out.println System.out System System.out X_500*1000+X_5*5 X_500*1000 X_500 1000 X_5*5 X_5 5 System.out.println(X_500*1000) System.out.println System.out System System.out X_500*1000 X_500 1000 String[] args args
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    
    int X_500 = X / 500;
    if (X%500 > 0){
      int X_5 = (X - X_500*500)/5;
      System.out.println(X_500*1000+X_5*5);
    }
    else
      System.out.println(X_500*1000);
    
  }
}