#include <bits/stdc++.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>

using namespace std;
using boost::algorithm::split;
using boost::algorithm::join;
using boost::algorithm::replace_all;

typedef long long ll;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long> llv;
typedef vector<double> dv;

#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
#define MOD 1000000007;
#define PI 3.141592653589793

template <typename T, template <typename TYPE, typename=std::allocator<TYPE>> class C>
class utils_C{
public:
    void resize(size_t size){container.resize(size);}
    void push(T value){container.push_back(value);}
    void push(C<T> value){rep(i,value.size())container.push_back(value[i]);}
    C<T> get(){return container;};
    T at(size_t index){return container[index];}
    size_t size(){return container.size();};
    size_t count(size_t first,size_t last,T target){return count(container.begin()+first,container.end()+last,target);}
    void swap(size_t l,size_t r){T temp=container[l];container[l]=container[r];container[r]=temp;}
    void asc_sort(size_t first,size_t last){sort(container.begin()+first,container.end()+last);}
    void des_sort(size_t first,size_t last){sort(container.begin()+first,container.end()+last,std::greater<T>());}
    //FOR_DEBUG
    void show(){rep(i,container.size())cout<<container[i]<<",";}
private:
    C<T> container;
};

template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    std::reverse(ret.begin(), ret.end());

    return ret;
}

vector<unsigned long> decompositPrime(unsigned long n)
{
    unsigned long a = 2;
    vector<unsigned long>ans;
    while (n >= a * a) {
        if (n % a == 0) {
            ans.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    ans.push_back(n);
    return ans;
}

bool IsPrime(unsigned long num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    long double sqrtNum = sqrt(num);
    for (unsigned long  i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}
bool pairCompare(const pair<int,int>& firstElof, const pair<int,int>& secondElof)
{
    return firstElof.second > secondElof.second;
}
bool divisible(llv&v,ll target,ll st){
    auto itr = find_if(v.begin(),v.begin()+st,[&](ll n){return target%n==0;});
    if(itr!=v.begin()+st)return true;
    itr = find_if(v.begin()+st+1,v.end(),[&](ll n){return target%n==0;});
    if(itr!=v.end())return true;
    else return false;
}
bool divisible_sd(llv&v,ll target,ll st){
    auto itr = find_if(v.begin(),v.begin()+st,[&](ll n){return target%n==0;});
    if(itr!=v.begin()+st)return true;
    else return false;
}


int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << std::setprecision(15);
    //
    int s;
    cin>>s;
    if(s%1000>0)cout<<1000-(s-(1000*(s/1000)));
    else cout<<0;
    return 0;
}


Measured memory_bytes: 3636