import java .util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  }
} import java .util.Scanner; Scanner java .util public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  } main {
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long s=sc.nextLong(); s sc.nextLong() sc.nextLong sc long p p q q r; r p=s/500 p s/500 s 500 q=(s%500)/5 q (s%500)/5 (s%500) s 500 5 r=p*1000+q*5 r p*1000+q*5 p*1000 p 1000 q*5 q 5 System.out.print(r) System.out.print System.out System System.out r String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  }
} Main
import java .util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long p,q,r;
    p=s/500;
    q=(s%500)/5;
    r=p*1000+q*5;
    System.out.print(r);
  }
}