import java.util.*;
import java.io.*;
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int x = Integer.parseInt(in.readLine());
    int ans = 0;
    while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    }
    System.out.println(ans);
  }
} import java.util.*; util.* java import java.io.*; io.* java public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int x = Integer.parseInt(in.readLine());
    int ans = 0;
    while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    }
    System.out.println(ans);
  }
} Main public static void main(String[] args)throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int x = Integer.parseInt(in.readLine());
    int ans = 0;
    while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    }
    System.out.println(ans);
  } main {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int x = Integer.parseInt(in.readLine());
    int ans = 0;
    while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    }
    System.out.println(ans);
  } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) int x = Integer.parseInt(in.readLine()); x Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in int ans = 0; ans 0 while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    } x >= 5 x 5 {
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    } if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      } x >= 500 x 500 {
        ans += 1000 * (x / 500);
        x %= 500;
      } ans += 1000 * (x / 500) ans 1000 * (x / 500) 1000 (x / 500) x 500 x %= 500 x 500 {
        ans += 5 * (x/5);
        x %= 5;
      } ans += 5 * (x/5) ans 5 * (x/5) 5 (x/5) x 5 x %= 5 x 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)throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int x = Integer.parseInt(in.readLine());
    int ans = 0;
    while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    }
    System.out.println(ans);
  }
} public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int x = Integer.parseInt(in.readLine());
    int ans = 0;
    while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    }
    System.out.println(ans);
  }
} Main
import java.util.*;
import java.io.*;
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int x = Integer.parseInt(in.readLine());
    int ans = 0;
    while(x >= 5){
      if(x >= 500){
        ans += 1000 * (x / 500);
        x %= 500;
      } else {
        ans += 5 * (x/5);
        x %= 5;
      }
    }
    System.out.println(ans);
  }
}