import std.conv, std.stdio;
import std.algorithm, std.array, std.string, std.range;

void main()
{
    auto
        x = readln.chomp.to!int,
        t = x / 500,
        s = (x % 500) / 5;
    (t * 1000 + s * 5).writeln;
}
