import java.util.ArrayDeque;
import java.lang.reflect.Array;
import java.util.Arrays;

import sun.tools.jar.resources.jar;

import java.util.*;

public class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  }
} import java.util.ArrayDeque; ArrayDeque java.util import java.lang.reflect.Array; Array java.lang.reflect import java.util.Arrays; Arrays java.util import sun.tools.jar.resources.jar; jar sun.tools.jar.resources import java.util.*; util.* java public class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  }
} Main public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  } main {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N = sc.nextInt(); N sc.nextInt() sc.nextInt sc long a = N / 500; a N / 500 N 500 N %= 500 N 500 long b = N / 5; b N / 5 N 5 System.out.println(1000 * a + (5 * b)) System.out.println System.out System System.out 1000 * a + (5 * b) 1000 * a 1000 a (5 * b) 5 b String args[] args public class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  }
} public class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  }
} Main
import java.util.ArrayDeque;
import java.lang.reflect.Array;
import java.util.Arrays;

import sun.tools.jar.resources.jar;

import java.util.*;

public class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  }
}
