import java.util.*;

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int u500 =0, u5 =0;
    u500 = X / 500 * 1000;
    u5 = X % 500 / 5 * 5;
    System.out.println(u500 + u5);
  }
}