import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  } main {
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X=sc.nextInt(); X sc.nextInt() sc.nextInt sc int a=X%500; a X%500 X 500 int Y=X-a; Y X-a X a int N=Y/500; N Y/500 Y 500 int b=a%5; b a%5 a 5 int Z=a-b; Z a-b a b int M=Z/5; M Z/5 Z 5 System.out.println((1000*N)+(5*M)) System.out.println System.out System System.out (1000*N)+(5*M) (1000*N) 1000 N (5*M) 5 M String[] args args public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  }
} public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  }
}