import java.util.*;

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

    int a = yen / 500;

    yen = yen - (500 * a);
    int b = yen / 5;

    System.out.println((a * 1000) + (b * 5));
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int yen = sc.nextInt();

    int a = yen / 500;

    yen = yen - (500 * a);
    int b = yen / 5;

    System.out.println((a * 1000) + (b * 5));
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int yen = sc.nextInt();

    int a = yen / 500;

    yen = yen - (500 * a);
    int b = yen / 5;

    System.out.println((a * 1000) + (b * 5));
  } main {
    Scanner sc = new Scanner(System.in);
    int yen = sc.nextInt();

    int a = yen / 500;

    yen = yen - (500 * a);
    int b = yen / 5;

    System.out.println((a * 1000) + (b * 5));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int yen = sc.nextInt(); yen sc.nextInt() sc.nextInt sc int a = yen / 500; a yen / 500 yen 500 yen = yen - (500 * a) yen yen - (500 * a) yen (500 * a) 500 a int b = yen / 5; b yen / 5 yen 5 System.out.println((a * 1000) + (b * 5)) System.out.println System.out System System.out (a * 1000) + (b * 5) (a * 1000) a 1000 (b * 5) b 5 String[] args args
import java.util.*;

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

    int a = yen / 500;

    yen = yen - (500 * a);
    int b = yen / 5;

    System.out.println((a * 1000) + (b * 5));
  }
}