#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
#define mod 1000000007
//#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;

ll gcd(ll a,ll b){
    if(a<b) return gcd(b,a);
    ll r;
    while((r=a%b)){
        a = b;
        b = r;
    }
    return b;
}
struct Frac{
    ll ue,sita;
    Frac():ue(0),sita(1){}
    Frac(ll n):ue(n),sita(1){}
    Frac(ll a,ll b):ue(a),sita(b){yakubun();}
    void yakubun(){
        if(ue == 0){
            sita = 1;
            return;
        }
        ll gc = gcd(abs(ue),abs(sita));
        ue /= gc;
        sita /= gc;
        if(sita < 0){
            ue *= -1;
            sita *= -1;
        }
    }
    const Frac operator+(const Frac& a){
        return Frac(this->ue*a.sita+a.ue*this->sita,this->sita*a.sita);
    }
    const Frac operator-(const Frac& a){
        return Frac(this->ue*a.sita-a.ue*this->sita,this->sita*a.sita);
    }
    const Frac operator*(const Frac& a){
        return Frac(this->ue*a.ue,this->sita*a.sita);
    }
    const Frac operator/(const Frac& a){
        return Frac(this->ue*a.sita,this->sita*a.ue);
    }
    bool operator==(const Frac& a){
        return (this->ue == a.ue) && (this->sita == a.sita);
    }
    bool operator!=(const Frac& a){
        return (this->ue != a.ue) || (this->sita != a.sita);
    }
    bool operator<(const Frac& a){
        return this->ue*a.sita < a.ue*this->sita;
    }
    bool operator<=(const Frac& a){
        return this->ue*a.sita <= a.ue*this->sita;
    }
    bool operator>(const Frac& a){
        return this->ue*a.sita > a.ue*this->sita;
    }
    bool operator>=(const Frac& a){
        return this->ue*a.sita >= a.ue*this->sita;
    }
    bool operator==(const ll& a){
        return (this->ue == a) && (this->sita == 1);
    }
    bool operator!=(const ll& a){
        return (this->ue != a) || (this->sita != 1);
    }
    bool operator<(const ll& a){
        return this->ue < a*this->sita;
    }
    bool operator<=(const ll& a){
        return this->ue <= a*this->sita;
    }
    bool operator>(const ll& a){
        return this->ue > a*this->sita;
    }
    bool operator>=(const ll& a){
        return this->ue >= a*this->sita;
    }

};

//行列式の存在は仮定
Frac det(vector<vector<Frac> > g){
    ll n = g.size();
    rep(i,n){
        if(g[i][i] == 0){
            for(ll j=i+1;j<n;++j){
                if(g[j][i] != 0){
                    for(ll k=i;k<n;++k){
                        g[i][k] = g[i][k]+g[j][k];
                    }
                    break;
                }
            }
        }
        for(ll j=i+1;j<n;++j){
            Frac kesu = g[j][i]/g[i][i];
            for(ll k=i;k<n;++k){
                Frac tmp = kesu*g[i][k];
                g[j][k] = g[j][k]-tmp;
            }
        }
    }
    Frac ret(1);
    rep(i,n) ret = ret*g[i][i];
    return ret;
}

void gyoswap(vector<vector<Frac> > &a,ll i,ll j){
    ll n = a.size();
    rep(k,n){
        Frac tmp = a[i][k];
        a[i][k] = a[j][k];
        a[j][k] = tmp;
    }
}

void retuswap(vector<vector<Frac> > &a,ll i,ll j){
    ll n = a.size();
    rep(k,n){
        Frac tmp = a[k][i];
        a[k][i] = a[k][j];
        a[k][j] = tmp;
    }
}

//逆行列の存在は仮定する(det(a) != 0)
vector<vector<Frac> > invMatrix(vector<vector<Frac> > g){
    ll n = g.size();
    vector<vector<Frac> > e(n,vector<Frac>(n,0));
    rep(i,n) e[i][i] = 1;
    //aの対角成分を非0にする
    rep(i,n){
        if(g[i][i] == 0){
            for(ll j=i+1;j<n;++j){
                if(g[j][i] != 0){
                    for(ll k=i;k<n;++k){
                        g[i][k] = g[i][k]+g[j][k];
                        e[i][k] = e[i][k]+e[j][k];
                    }
                    break;
                }
            }
        }
        for(ll j=0;j<n;++j){
            if(j == i) continue;
            Frac kesu = g[j][i]/g[i][i];
            for(ll k=0;k<n;++k){
                Frac tmp = kesu*g[i][k];
                g[j][k] = g[j][k]-tmp;
                e[j][k] = e[j][k]-(kesu*e[i][k]);
            }
        }
    }
    rep(i,n){
        rep(j,n) e[i][j] = e[i][j]/g[i][i];
        g[i][i] = g[i][i]/g[i][i];
    }
    return e;
}

vector<vector<Frac> > dot(vector<vector<Frac> > &a,vector<vector<Frac> > &b){
    vector<vector<Frac> > ret(a.size(),vector<Frac>(b[0].size(),0));
    rep(i,ret.size()){
        rep(j,ret[i].size()){
            rep(k,a[0].size()){
                ret[i][j] = ret[i][j]+(a[i][k]*b[k][j]);
            }
        }
    }
    return ret;
}

int main(){
    ll n;
    cin>>n;
    ll maisu = 0;
    while(maisu*1000 < n) maisu++;
    cout<<(maisu*1000-n)<<endl;
    return 0;
}


Measured memory_bytes: 3652