import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int X = sc.nextInt();
		sc.close();

		int answer = 0;

		int fivehundred = X / 500 ;
		int five = (X - fivehundred*500) / 5;

		System.out.println(fivehundred*1000 + five*5);
	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int X = sc.nextInt();
		sc.close();

		int answer = 0;

		int fivehundred = X / 500 ;
		int five = (X - fivehundred*500) / 5;

		System.out.println(fivehundred*1000 + five*5);
	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int X = sc.nextInt();
		sc.close();

		int answer = 0;

		int fivehundred = X / 500 ;
		int five = (X - fivehundred*500) / 5;

		System.out.println(fivehundred*1000 + five*5);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int X = sc.nextInt();
		sc.close();

		int answer = 0;

		int fivehundred = X / 500 ;
		int five = (X - fivehundred*500) / 5;

		System.out.println(fivehundred*1000 + five*5);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc sc.close() sc.close sc int answer = 0; answer 0 int fivehundred = X / 500 ; fivehundred X / 500 X 500 int five = (X - fivehundred*500) / 5; five (X - fivehundred*500) / 5 (X - fivehundred*500) X fivehundred*500 fivehundred 500 5 System.out.println(fivehundred*1000 + five*5) System.out.println System.out System System.out fivehundred*1000 + five*5 fivehundred*1000 fivehundred 1000 five*5 five 5 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int X = sc.nextInt();
		sc.close();

		int answer = 0;

		int fivehundred = X / 500 ;
		int five = (X - fivehundred*500) / 5;

		System.out.println(fivehundred*1000 + five*5);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int X = sc.nextInt();
		sc.close();

		int answer = 0;

		int fivehundred = X / 500 ;
		int five = (X - fivehundred*500) / 5;

		System.out.println(fivehundred*1000 + five*5);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int X = sc.nextInt();
		sc.close();

		int answer = 0;

		int fivehundred = X / 500 ;
		int five = (X - fivehundred*500) / 5;

		System.out.println(fivehundred*1000 + five*5);
	}

}
