import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = x/500;
    int b = x - (a*500);
    int c = b/5;

    int ans1 = a*1000;
    int ans2 = c*5;

    System.out.println(ans1+ans2);
  }
} 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 a = x/500;
    int b = x - (a*500);
    int c = b/5;

    int ans1 = a*1000;
    int ans2 = c*5;

    System.out.println(ans1+ans2);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = x/500;
    int b = x - (a*500);
    int c = b/5;

    int ans1 = a*1000;
    int ans2 = c*5;

    System.out.println(ans1+ans2);
  } main {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = x/500;
    int b = x - (a*500);
    int c = b/5;

    int ans1 = a*1000;
    int ans2 = c*5;

    System.out.println(ans1+ans2);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int a = x/500; a x/500 x 500 int b = x - (a*500); b x - (a*500) x (a*500) a 500 int c = b/5; c b/5 b 5 int ans1 = a*1000; ans1 a*1000 a 1000 int ans2 = c*5; ans2 c*5 c 5 System.out.println(ans1+ans2) System.out.println System.out System System.out ans1+ans2 ans1 ans2 String[] args args public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = x/500;
    int b = x - (a*500);
    int c = b/5;

    int ans1 = a*1000;
    int ans2 = c*5;

    System.out.println(ans1+ans2);
  }
} public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = x/500;
    int b = x - (a*500);
    int c = b/5;

    int ans1 = a*1000;
    int ans2 = c*5;

    System.out.println(ans1+ans2);
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = x/500;
    int b = x - (a*500);
    int c = b/5;

    int ans1 = a*1000;
    int ans2 = c*5;

    System.out.println(ans1+ans2);
  }
}
