import java.util.Scanner;

/**
 * B - Golden Coins
 */
public class Main {
  @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  }
} Main @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int val = 0; val 0 if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    } N != 0 N 0 {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    } val = (N / 500) * 1000 val (N / 500) * 1000 (N / 500) N 500 1000 val += (N % 500) / 5 * 5 val (N % 500) / 5 * 5 (N % 500) / 5 (N % 500) N 500 5 5 System.out.println(val) System.out.println System.out System System.out val String[] args args public class Main {
  @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  }
} public class Main {
  @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  }
} Main
import java.util.Scanner;

/**
 * B - Golden Coins
 */
public class Main {
  @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  }
}