import java.util.Scanner;
class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int X = scan.nextInt();
 int a = 0;
 int b = 0;
 int sum = 0;
   //500円換算
  	if( X >= 1000 ){
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    }
  	else if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    }
   //5円換算
	X = X / 5;
    X = X * 5;
    sum = sum + X;
  
  System.out.println(sum);
 }
} import java.util.Scanner; Scanner java.util class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int X = scan.nextInt();
 int a = 0;
 int b = 0;
 int sum = 0;
   //500円換算
  	if( X >= 1000 ){
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    }
  	else if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    }
   //5円換算
	X = X / 5;
    X = X * 5;
    sum = sum + X;
  
  System.out.println(sum);
 }
} Main public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int X = scan.nextInt();
 int a = 0;
 int b = 0;
 int sum = 0;
   //500円換算
  	if( X >= 1000 ){
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    }
  	else if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    }
   //5円換算
	X = X / 5;
    X = X * 5;
    sum = sum + X;
  
  System.out.println(sum);
 } main {
 Scanner scan = new Scanner(System.in);
 
 int X = scan.nextInt();
 int a = 0;
 int b = 0;
 int sum = 0;
   //500円換算
  	if( X >= 1000 ){
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    }
  	else if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    }
   //5円換算
	X = X / 5;
    X = X * 5;
    sum = sum + X;
  
  System.out.println(sum);
 } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int X = scan.nextInt(); X scan.nextInt() scan.nextInt scan int a = 0; a 0 int b = 0; b 0 int sum = 0; sum 0 if( X >= 1000 ){
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    }
  	else if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    } X >= 1000 X 1000 {
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    } a = X / 500 a X / 500 X 500 sum = 1000 * a sum 1000 * a 1000 a a = 500 * a a 500 * a 500 a X = X - a X X - a X a if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    } X >= 500 X 500 {
      X = X - 500;
      sum = 1000;
    } X = X - 500 X X - 500 X 500 sum = 1000 sum 1000 {
    } X = X / 5 X X / 5 X 5 X = X * 5 X X * 5 X 5 sum = sum + X sum sum + X sum X System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.util.Scanner;
class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int X = scan.nextInt();
 int a = 0;
 int b = 0;
 int sum = 0;
   //500円換算
  	if( X >= 1000 ){
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    }
  	else if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    }
   //5円換算
	X = X / 5;
    X = X * 5;
    sum = sum + X;
  
  System.out.println(sum);
 }
}