import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int c = scanner.nextInt();
    System.out.println(ans(c));
  }
  
  public static int ans(int c) {
    int h = 0;
    if(c == 0) { 
      return 0;
    } else {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    }
  }
} import java.util.Scanner; Scanner java.util class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int c = scanner.nextInt();
    System.out.println(ans(c));
  }
  
  public static int ans(int c) {
    int h = 0;
    if(c == 0) { 
      return 0;
    } else {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    }
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int c = scanner.nextInt();
    System.out.println(ans(c));
  } main {
    Scanner scanner = new Scanner(System.in);
    int c = scanner.nextInt();
    System.out.println(ans(c));
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner System.out.println(ans(c)) System.out.println System.out System System.out ans(c) ans c String[] args args public static int ans(int c) {
    int h = 0;
    if(c == 0) { 
      return 0;
    } else {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    }
  } ans {
    int h = 0;
    if(c == 0) { 
      return 0;
    } else {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    }
  } int h = 0; h 0 if(c == 0) { 
      return 0;
    } else {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    } c == 0 c 0 { 
      return 0;
    } return 0; 0 {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    } int fh = c/500; fh c/500 c 500 c = c%500 c c%500 c 500 int f = c/5; f c/5 c 5 h = fh*1000 + f*5 h fh*1000 + f*5 fh*1000 fh 1000 f*5 f 5 return h; h int c c
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int c = scanner.nextInt();
    System.out.println(ans(c));
  }
  
  public static int ans(int c) {
    int h = 0;
    if(c == 0) { 
      return 0;
    } else {
      int fh = c/500;
      c = c%500;
      int f = c/5;
      h = fh*1000 + f*5;
      return h;
    }
  }
}
