import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int happiness = 0;
    if (X >= 500) {
      happiness = (X/500)*1000;
      X -= (X/500)*500;
      
    }
    happiness += (X/5)*5;
    System.out.println(happiness);
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int happiness = 0;
    if (X >= 500) {
      happiness = (X/500)*1000;
      X -= (X/500)*500;
      
    }
    happiness += (X/5)*5;
    System.out.println(happiness);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int happiness = 0;
    if (X >= 500) {
      happiness = (X/500)*1000;
      X -= (X/500)*500;
      
    }
    happiness += (X/5)*5;
    System.out.println(happiness);
  } main {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int happiness = 0;
    if (X >= 500) {
      happiness = (X/500)*1000;
      X -= (X/500)*500;
      
    }
    happiness += (X/5)*5;
    System.out.println(happiness);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int happiness = 0; happiness 0 if (X >= 500) {
      happiness = (X/500)*1000;
      X -= (X/500)*500;
      
    } X >= 500 X 500 {
      happiness = (X/500)*1000;
      X -= (X/500)*500;
      
    } happiness = (X/500)*1000 happiness (X/500)*1000 (X/500) X 500 1000 X -= (X/500)*500 X (X/500)*500 (X/500) X 500 500 happiness += (X/5)*5 happiness (X/5)*5 (X/5) X 5 5 System.out.println(happiness) System.out.println System.out System System.out happiness 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 happiness = 0;
    if (X >= 500) {
      happiness = (X/500)*1000;
      X -= (X/500)*500;
      
    }
    happiness += (X/5)*5;
    System.out.println(happiness);
  }
}