import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int N = Integer.parseInt(st.nextToken()); N Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int x = N / 500; x N / 500 N 500 int sum = x * 1000; sum x * 1000 x 1000 N %= 500 N 500 sum += (N / 5) * 5 sum (N / 5) * 5 (N / 5) N 5 5 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int x = N / 500;
		int sum = x * 1000;
		N %= 500;
		sum += (N / 5) * 5;
		System.out.println(sum);
	}
}