import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;



        System.out.println(uresisa);
    }
} import java.util.*; util.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;



        System.out.println(uresisa);
    }
} Main public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;



        System.out.println(uresisa);
    } main {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;



        System.out.println(uresisa);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = Integer.parseInt(scanner.next()); n Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int gohyaku =0 gohyaku 0 hyaku = 0 hyaku 0 gozyu = 0 gozyu 0 zyu = 0 zyu 0 go = 0 go 0 ichi = 0; ichi 0 int sum = 0; sum 0 int uresisa = 0; uresisa 0 gohyaku = n / 500 gohyaku n / 500 n 500 sum += gohyaku * 500 sum gohyaku * 500 gohyaku 500 hyaku = (n - sum) / 100 hyaku (n - sum) / 100 (n - sum) n sum 100 sum += (hyaku * 100) sum (hyaku * 100) hyaku 100 gozyu = (n - sum) / 50 gozyu (n - sum) / 50 (n - sum) n sum 50 sum += gozyu * 50 sum gozyu * 50 gozyu 50 zyu = (n-sum) / 10 zyu (n-sum) / 10 (n-sum) n sum 10 sum += zyu * 10 sum zyu * 10 zyu 10 go = (n-sum) / 5 go (n-sum) / 5 (n-sum) n sum 5 sum += go * 5 sum go * 5 go 5 ichi = n - sum ichi n - sum n sum sum += ichi sum ichi uresisa += gohyaku * 1000 uresisa gohyaku * 1000 gohyaku 1000 uresisa += hyaku * 100 uresisa hyaku * 100 hyaku 100 uresisa += gozyu * 50 uresisa gozyu * 50 gozyu 50 uresisa += zyu * 10 uresisa zyu * 10 zyu 10 uresisa += go * 5 uresisa go * 5 go 5 System.out.println(uresisa) System.out.println System.out System System.out uresisa String[] args args public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;



        System.out.println(uresisa);
    }
} public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;



        System.out.println(uresisa);
    }
} Main
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;



        System.out.println(uresisa);
    }
}