import java.util.Scanner;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  }
}
class Logic{
  public static int run(int x){
    int joy = 0;
    joy += (x / 500) * 1000;
    x = x % 500;
    joy += (x / 5) * 5;
    return joy;
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  }
} Main public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  } main {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc System.out.print(Logic.run(x)) System.out.print System.out System System.out Logic.run(x) Logic.run Logic x String args[] args class Logic{
  public static int run(int x){
    int joy = 0;
    joy += (x / 500) * 1000;
    x = x % 500;
    joy += (x / 5) * 5;
    return joy;
  }
} Logic public static int run(int x){
    int joy = 0;
    joy += (x / 500) * 1000;
    x = x % 500;
    joy += (x / 5) * 5;
    return joy;
  } run {
    int joy = 0;
    joy += (x / 500) * 1000;
    x = x % 500;
    joy += (x / 5) * 5;
    return joy;
  } int joy = 0; joy 0 joy += (x / 500) * 1000 joy (x / 500) * 1000 (x / 500) x 500 1000 x = x % 500 x x % 500 x 500 joy += (x / 5) * 5 joy (x / 5) * 5 (x / 5) x 5 5 return joy; joy int x x public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  }
} public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  }
} Main
import java.util.Scanner;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  }
}
class Logic{
  public static int run(int x){
    int joy = 0;
    joy += (x / 500) * 1000;
    x = x % 500;
    joy += (x / 5) * 5;
    return joy;
  }
}