

import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    }



} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    }



} Main public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    } main {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int a = input.nextInt(); a input.nextInt() input.nextInt input int c = a/500; c a/500 a 500 int b = a%500; b a%500 a 500 int remainder = b%5; remainder b%5 b 5 System.out.println(1000*c+(b-remainder)) System.out.println System.out System System.out 1000*c+(b-remainder) 1000*c 1000 c (b-remainder) b remainder String[] args args public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    }



} public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    }



} Main


import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    }



}