#import <Foundation/Foundation.h>
#import <stdio.h>

int main(int argc, char **argv) {
  NSInteger amount;
  scanf("%ld", &amount);
  NSInteger fiveHundred = amount / 500;
  amount %= 500;
  NSInteger five = amount / 5;
  NSInteger happy = fiveHundred * 1000 + five * 5;
  
  printf("%ld", happy);
  return 0;
}