#include <iostream>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
int count = 0;
cin >> n;
n = 1000 - n;
count += (n / 500);
n = n % 500;
count += (n / 100);
n = n % 100;
count += (n / 50);
n = n % 50;
count += (n / 10);
n = n % 10;
count += (n / 5);
n = n % 5;
count += n;
cout << count << "\n";
return 0;
}