#include <stdio.h>
int Q[] = { 500, 200, 100, 50, 20, 10 };
int main()
{
int n, q, x;
scanf("%d",&n);
x=0;
for(int i = 0; i < 6; ++i)
{
q = Q[i];
x += n / q;
n %= q;
}
if(n > 0) x = -1;
printf("%d",x);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgUVtdID0geyA1MDAsIDIwMCwgMTAwLCA1MCwgMjAsIDEwIH07CgppbnQgbWFpbigpCnsKIGludCBuLCBxLCB4Owogc2NhbmYoIiVkIiwmbik7CiB4PTA7CiAKIGZvcihpbnQgaSA9IDA7IGkgPCA2OyArK2kpCiB7CiAgICBxID0gUVtpXTsKICAgIHggKz0gbiAvIHE7CiAgICBuICU9IHE7CiB9CiAKIGlmKG4gPiAwKSB4ID0gLTE7CiAKIHByaW50ZigiJWQiLHgpOwogCiByZXR1cm4gMDsKfQo=