import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    }
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    }
  } main {
    Scanner sc = new Scanner(System.in);
    try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    } {
      sc.close();
    } sc.close() sc.close sc {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc long ans = 0; ans 0 ans += n / 500 * 1000 ans n / 500 * 1000 n / 500 n 500 1000 n %= 500 n 500 ans += n / 5 * 5 ans n / 5 * 5 n / 5 n 5 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    }
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      long n = sc.nextLong();
      long ans = 0;

      ans += n / 500 * 1000;
      n %= 500;

      ans += n / 5 * 5;
      System.out.println(ans);
    } finally {
      sc.close();
    }
  }
}
