#include <bits/stdc++.h>
using namespace std;
class FastReader {
public:
FastReader() { ios::sync_with_stdio(false); cin.tie(nullptr); }
int nextInt() { int x; cin >> x; return x; }
};
class FastWriter {
public:
void print(long long x) { cout << x; }
};
int main() {
try {
FastReader in;
FastWriter out;
int testcases = 1; /* testcases = in.nextInt(); */
while (testcases-- > 0) {
int tokens = in.nextInt();
int type1 = tokens / 500;
tokens %= 500;
int type2 = tokens / 5;
long long ans = type1 * 1000LL + type2 * 5LL;
out.print(ans);
}
} catch (exception& e) {
cerr << e.what() << endl;
return 1;
}
return 0;
}