#include <bits/stdc++.h>
using namespace std;
 
 
void solve(){
  int main,temp,count=0;
  cin>>main;

  temp=floor(main/500);
  main=main-temp*500;
  count=count+temp*1000;
  count=count+floor(main/5)*5;
  cout<<count;
  return;

}



int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int t=1;
  //cin>>t;
  while(t--) solve();
}

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string S; cin >> S; reverse(ALL(S)); cout << S << "\n";
	return 0;
}