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

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

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