a = int(input()) # 1260 대입
b = a//500 # b=2 c = a-b*500 # c=260 d = c//100 # d=2 e = c-d*100 # e=60 f = e//50 # f=1 g = e-f*50 # g=10 h = g//10 # h=1
count = b+d+f+h
print(count)