#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
#define MAX 100000
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

int N = 1000000;
int NOD[1000000];
void generateNOD()
{
    for (int i = 0; i <= N; i++)
    {
        for (int j = i; j <= N; j += i)
        {
            NOD[j]++;
        }
    }
}
int main()
{
    int n;
    cin >> n;
    int yen500 = 1000 * (n / 500);
    int left = n % 500;
    int yen5 = 5 * (left / 5);
    cout << yen500 + yen5 << endl;

}

#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        int n; cin >> n;
        int ans = 0;
        while(n >= 500)
        {
            int x = n/500;
            ans += x*1000;
            n -= (x)*500;
        }
        while(n >= 5)
        {
            int y = n/5;
            ans += y*5;
            n -= y*5;
        }
        cout << ans;
    }    
}