import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int number500 = 0;
        int number5 = 0;
        while (x >= 500) {
            number500++;
            x -= 500;
        }
        while (x >= 5) {
            number5++;
            x -= 5;
        }
        int happy = 1000 * number500 + 5 * number5;
        System.out.println(happy);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int number500 = 0;
        int number5 = 0;
        while (x >= 500) {
            number500++;
            x -= 500;
        }
        while (x >= 5) {
            number5++;
            x -= 5;
        }
        int happy = 1000 * number500 + 5 * number5;
        System.out.println(happy);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int number500 = 0;
        int number5 = 0;
        while (x >= 500) {
            number500++;
            x -= 500;
        }
        while (x >= 5) {
            number5++;
            x -= 5;
        }
        int happy = 1000 * number500 + 5 * number5;
        System.out.println(happy);
    } main {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int number500 = 0;
        int number5 = 0;
        while (x >= 500) {
            number500++;
            x -= 500;
        }
        while (x >= 5) {
            number5++;
            x -= 5;
        }
        int happy = 1000 * number500 + 5 * number5;
        System.out.println(happy);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int number500 = 0; number500 0 int number5 = 0; number5 0 while (x >= 500) {
            number500++;
            x -= 500;
        } x >= 500 x 500 {
            number500++;
            x -= 500;
        } number500++ number500 x -= 500 x 500 while (x >= 5) {
            number5++;
            x -= 5;
        } x >= 5 x 5 {
            number5++;
            x -= 5;
        } number5++ number5 x -= 5 x 5 int happy = 1000 * number500 + 5 * number5; happy 1000 * number500 + 5 * number5 1000 * number500 1000 number500 5 * number5 5 number5 System.out.println(happy) System.out.println System.out System System.out happy String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int number500 = 0;
        int number5 = 0;
        while (x >= 500) {
            number500++;
            x -= 500;
        }
        while (x >= 5) {
            number5++;
            x -= 5;
        }
        int happy = 1000 * number500 + 5 * number5;
        System.out.println(happy);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int number500 = 0;
        int number5 = 0;
        while (x >= 500) {
            number500++;
            x -= 500;
        }
        while (x >= 5) {
            number5++;
            x -= 5;
        }
        int happy = 1000 * number500 + 5 * number5;
        System.out.println(happy);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int number500 = 0;
        int number5 = 0;
        while (x >= 500) {
            number500++;
            x -= 500;
        }
        while (x >= 5) {
            number5++;
            x -= 5;
        }
        int happy = 1000 * number500 + 5 * number5;
        System.out.println(happy);
    }
}