import java.io.*;

public class Main {
  
  static long n;

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  }
} import java.io.*; io.* java public class Main {
  
  static long n;

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  }
} Main static long n; n public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  } main {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] in; in in = br.readLine().split(" ") in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Long.parseLong(in[0]) n Long.parseLong(in[0]) Long.parseLong Long in[0] in 0 br.close() br.close br long ans = 0; ans 0 ans += (n / 500) * 1000 ans (n / 500) * 1000 (n / 500) n 500 1000 n -= n / 500 * 500 n n / 500 * 500 n / 500 n 500 500 ans += n / 5 * 5 ans n / 5 * 5 n / 5 n 5 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  
  static long n;

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  }
} public class Main {
  
  static long n;

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  }
} Main
import java.io.*;

public class Main {
  
  static long n;

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  }
}