import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long X = sc.nextLong(); X sc.nextLong() sc.nextLong sc long ans = 0; ans 0 while(X>=500){
      ans += 1000;
      X -= 500;
    } X>=500 X 500 {
      ans += 1000;
      X -= 500;
    } ans += 1000 ans 1000 X -= 500 X 500 while(X>=5){
      ans += 5;
      X -= 5;
    } X>=5 X 5 {
      ans += 5;
      X -= 5;
    } ans += 5 ans 5 X -= 5 X 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  }
} Main
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long ans = 0;
    while(X>=500){
      ans += 1000;
      X -= 500;
    }
    while(X>=5){
      ans += 5;
      X -= 5;
    }
    System.out.println(ans);
  }
}