def main():

    n = int(eval(input()))

    ans = 1000*(n//500)

    n %= 500

    ans += 5*(n//5)

    print(ans)





main()

def main():

    x = int(eval(input()))

    cnt = 0

    cnt += 1000*(x//500)

    x %= 500

    cnt += 5*(x//5)

    print(cnt)





main()

def main():
    n = int(eval(input()))
    ans = 1000 * (n // 500)
    n %= 500
    ans += 5 * (n // 5)
    print(ans)


main()

def main():
    x = int(eval(input()))
    cnt = 0
    cnt += 1000 * (x // 500)
    x %= 500
    cnt += 5 * (x // 5)
    print(cnt)


main()

-    n = int(eval(input())) -    ans = 1000 * (n // 500) -    n %= 500 -    ans += 5 * (n // 5) -    print(ans) +    x = int(eval(input())) +    cnt = 0 +    cnt += 1000 * (x // 500) +    x %= 500 +    cnt += 5 * (x // 5) +    print(cnt)