def resolve():

    x=int(eval(input()))

    ans=0

    while x>=500:

        x-=500

        ans+=1000

    while x>=5:

        x-=5

        ans+=5

    print(ans)

resolve()
n=int(eval(input()))

gg=0

gg+=(n//500)*1000

n=n-(n//500)*500

gg+=(n//5)*5

print(gg)

def resolve():
    x = int(eval(input()))
    ans = 0
    while x >= 500:
        x -= 500
        ans += 1000
    while x >= 5:
        x -= 5
        ans += 5
    print(ans)


resolve()

n = int(eval(input()))
gg = 0
gg += (n // 500) * 1000
n = n - (n // 500) * 500
gg += (n // 5) * 5
print(gg)

-def resolve(): -    x = int(eval(input())) -    ans = 0 -    while x >= 500: -        x -= 500 -        ans += 1000 -    while x >= 5: -        x -= 5 -        ans += 5 -    print(ans) - - -resolve() +n = int(eval(input())) +gg = 0 +gg += (n // 500) * 1000 +n = n - (n // 500) * 500 +gg += (n // 5) * 5 +print(gg)