#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll happiness = 0;
	while(n >= 500){
		happiness += 1000;
		n -= 500;
	}
	while(n >= 5){
		happiness += 5;
		n -= 5;
	}
	cout << happiness << endl;
}



#include<iostream>

using namespace std;

const int coin[2] = {5,500};

int main(){
  int money,happy;
  cin >> money;
  int C[2] = {0,0};
  for(int i = 1;i >= 0;i--){
    C[i] = money / coin[i];
    money -= coin[i]*C[i];
  }
  happy = C[0]*5 + C[1]*1000;
  cout << happy << endl;
  return 0;
}