import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int count1=0;
    int count2=0;

    while(x>=500){
      x-=500;
      count1++;
    }

    while(x>=5){
      x-=5;
      count2++;
    }

    System.out.println(count1*1000+count2*5);

  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int count1=0;
    int count2=0;

    while(x>=500){
      x-=500;
      count1++;
    }

    while(x>=5){
      x-=5;
      count2++;
    }

    System.out.println(count1*1000+count2*5);

  }
} Main public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int count1=0;
    int count2=0;

    while(x>=500){
      x-=500;
      count1++;
    }

    while(x>=5){
      x-=5;
      count2++;
    }

    System.out.println(count1*1000+count2*5);

  } main {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int count1=0;
    int count2=0;

    while(x>=500){
      x-=500;
      count1++;
    }

    while(x>=5){
      x-=5;
      count2++;
    }

    System.out.println(count1*1000+count2*5);

  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int x=sc.nextInt(); x sc.nextInt() sc.nextInt sc int count1=0; count1 0 int count2=0; count2 0 while(x>=500){
      x-=500;
      count1++;
    } x>=500 x 500 {
      x-=500;
      count1++;
    } x-=500 x 500 count1++ count1 while(x>=5){
      x-=5;
      count2++;
    } x>=5 x 5 {
      x-=5;
      count2++;
    } x-=5 x 5 count2++ count2 System.out.println(count1*1000+count2*5) System.out.println System.out System System.out count1*1000+count2*5 count1*1000 count1 1000 count2*5 count2 5 String[] args args public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int count1=0;
    int count2=0;

    while(x>=500){
      x-=500;
      count1++;
    }

    while(x>=5){
      x-=5;
      count2++;
    }

    System.out.println(count1*1000+count2*5);

  }
} public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int count1=0;
    int count2=0;

    while(x>=500){
      x-=500;
      count1++;
    }

    while(x>=5){
      x-=5;
      count2++;
    }

    System.out.println(count1*1000+count2*5);

  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int count1=0;
    int count2=0;

    while(x>=500){
      x-=500;
      count1++;
    }

    while(x>=5){
      x-=5;
      count2++;
    }

    System.out.println(count1*1000+count2*5);

  }
}
