#include<bits/stdc++.h>
using namespace std;

#define For(i,a,b)                              for (int i=a;i<b;i++)
#define Forl(i,size)                            for (int i=0;i<size;i++)
#define Forr(i,size)                            for (int i=size-1;i>=0;i--)
#define s(n)                                    scanf("%d",&n)
#define p(n)                                    printf("%d\n",n)
#define ps(n)                                   printf("%s\n",n)
#define sd(n)                                   int n;scanf("%d",&n)
#define sl(n)                                   long long int n;scanf("%lld",&n)
#define pb(n)                                   push_back(n)
#define clr(a)                                  memset(a,0,sizeof(a))
#define all(c)                                  (c).begin(),(c).end()
#define len                                     length()
#define size                                     size()
#define mp(a,b)                                 make_pair(a,b)
#define fi first
#define se second
typedef unsigned long long ull;
#define ret return 0;
#define PI 3.14159265
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
const long long Mod =1e9+7; 
string a,b,s,c,d;

typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <string> vst;
typedef vector <bool> vb;
typedef long long ll;
ll sum=0,ans=0,res=0;
int i, j, k;


// IS PRIME FUNCTION STARTS   

bool isPrime(ll num){
    bool flag=true;
    if(num==1)return false;
    for(int i = 2; i <= sqrt(num); i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}

//IS PRIME FUNCTION ENDS


//**Array Sum Function**

ll findSum(ll a[],int l,int r)
{ll sum=0;
    For(i,l,r)
    {
        sum+=a[i];
    }
    return sum;
}

//**Array Sum Function Ends**


//Prime Factors Of A Number 

vector<pair<int,int>> vec1; //Prime Factors along with their exponents
void primeFactors(ll n) 
{ int c1=0;
	// Print the number of 2s that divide n 
	while (n%2 == 0) 
	{ 
		// printf("%d ", 2); 
		n = n/2;c1++; 
	} if(c1)
    vec1.pb(mp(2,c1));
c1=0;
	// n must be odd at this point. So we can skip 
	// one element (Note i = i +2) 
	for (int i = 3; i <= sqrt(n); i = i+2) 
	{ c1=0;
		// While i divides n, print i and divide n 
		while (n%i == 0) 
		{ 
			// printf("%d ", i); 
		    
            n = n/i;c1++; 
		} 
        if(c1)
        vec1.pb(mp(i,c1));
	} 
c1=0;
	// This condition is to handle the case when n 
	// is a prime number greater than 2 
	if (n > 2) 
	vec1.pb(mp(n,1));
} 

//Ends



//*** Power Function Starts
ll power(int x, unsigned int y) 
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
} 
//*** Power function ends 

//nCr function starts

ull nCr(ll n,ll r)
{
ull p=1;ull k=1;
if(n-r<r)
r=n-r;

if(r!=0)
{
    while(r)
    {
        p*=n;k*=r;
        ll m=__gcd(p,k);
        p/=m;k/=m;     //Simplifying 
        n--;r--;
    }

}
else p=1;

return p;


}


//nCr function ends


// ** LCM of two numbers
ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//** Ends //


//** Count Set Bits Functon

unsigned int countBits(ll n,int specify) 
{ 
    unsigned int count = 0,total=0; 
    if (n==0){if(specify == 1)return 0;else return 1;}
    while (n) { 
        total+=1;
        count += n & 1; 
        n >>= 1; 
    } 
    if(specify==1)
    return count; 
    else return (total-count);
}

//** Ends //


//Array Scanner starts

void scar(ll a[],int n)
{
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
}

//Array Scanner ends



signed main() 
    {
        int a;
        cin>>a;
        int b=0;
        b=b+1000*(a/500);
        a=a%500;
        b=b+5*(a/5);
        cout<<b<<endl;
    return 0;
    }

Measured memory_bytes: 256