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

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  }
} Main public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  } main {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  } Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) int x = in.nextInt(); x in.nextInt() in.nextInt in int ans = 0; ans 0 while (x >= 500) {
      ans += 1000;
      x -= 500;
    } x >= 500 x 500 {
      ans += 1000;
      x -= 500;
    } ans += 1000 ans 1000 x -= 500 x 500 while (x >= 5) {
      ans += 5;
      x -= 5;
    } x >= 5 x 5 {
      ans += 5;
      x -= 5;
    } ans += 5 ans 5 x -= 5 x 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  }
} public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int x = in.nextInt();
    int ans = 0;
    while (x >= 500) {
      ans += 1000;
      x -= 500;
    }
    while (x >= 5) {
      ans += 5;
      x -= 5;
    }
    System.out.println(ans);
  }
}
