import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    } main {
        Scanner sc = new Scanner(System.in);

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long haveMoney = sc.nextLong(); haveMoney sc.nextLong() sc.nextLong sc long pleasure = 0; pleasure 0 while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        } 500 <= haveMoney 500 haveMoney {
            haveMoney -= 500;
            pleasure += 1000;
        } haveMoney -= 500 haveMoney 500 pleasure += 1000 pleasure 1000 while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        } 5 <= haveMoney 5 haveMoney {
            haveMoney -= 5;
            pleasure += 5;
        } haveMoney -= 5 haveMoney 5 pleasure += 5 pleasure 5 System.out.println(pleasure) System.out.println System.out System System.out pleasure String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long haveMoney = sc.nextLong();
        long pleasure = 0;
        while(500 <= haveMoney){
            haveMoney -= 500;
            pleasure += 1000;
        }
        while(5 <= haveMoney){
            haveMoney -= 5;
            pleasure += 5;
        }
        System.out.println(pleasure);
    }
}