#include<bits/stdc++.h>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repi(i,a,b) for(ll i=b-1;i>=a;i--)
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long int>
#define pb push_back
#define mp make_pair
#define INF 1e18
#define S(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define deci(n) fixed << setprecision(n)
#define PI 3.141592653589793238462643
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll gcd(ll a,ll b){while(b){ll t=a;a=b;b=t%b;}return a;}     
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll power(ll a,ll b){ll r=1;while(b){if(b&1)r*=a;a=a*a;b>>=1;}return r;}

void pairsort(ll a[], ll b[], ll n) 
{ 
    pair<ll, ll> pairt[n]; 
  
 
    for (ll i = 0; i < n; i++)  
    { 
        pairt[i].first = a[i]; 
        pairt[i].second = b[i]; 
    } 
  
    sort(pairt, pairt + n); 
      
    for (ll i = 0; i < n; i++)  
    { 
        a[i] = pairt[i].first; 
        b[i] = pairt[i].second; 
    } 
}
 
ll extendedGcd(ll a, ll b, ll & x, ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = extendedGcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}


  ll binaryToDecimal(string n) 
{ 
    string num = n; 
    ll dec_value = 0; 
    // Initializing base value to 1, i.e 2^0 
    ll base = 1;  
    ll len = num.length(); 
    for (ll i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
    return dec_value; 
} 


ll nCr(ll n,ll k){ 
    ll C[n + 1][k + 1]; 
    ll i, j; 
    for (i=0;i<=n;i++){ 
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i) 
                C[i][j]=1;  
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B; 
        } 
    }
    return C[n][k]%B; 
} 


ll highestPowerof2(ll n) 
{ 
   ll p = (ll)log2(n); 
    return (ll)pow(2, p);  
} 
bool isPowerOfTwo(ll x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }


const double PI1 = acos(-1);

map<ll,ll> countDivisors(ll n) 
{ 
    ll cnt = 0; 
    map<ll,ll> m;
    for (ll i = 1; i <= sqrt(n); i++) 
    { 
        if (n % i == 0) 
        {  
         m[i]++;
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                {cnt = cnt + 2; 
                    m[n/i]++;}
        } 
    } 
    return m; 
} 


/*
map<int,vector<int> > m;
void bfs(int src)
{
    map<int,int> visited;
    queue<int> q;
    q.push(src);

    visited[src]=true;
    while(!q.empty())
        {
             int cur=q.front();
             q.pop();
             for(auto x:m[cur])
             {
                if(!visited[x])
                {
                    q.push(x);
                    visited[x]=true;
                }
             }
        }
}
*/
void dfs(int p,vector<int> a[],int v[])
{
    if(v[p])
        return ;
    v[p]=1;
    for(int i=0;i<(int)a[p].size();i++)
    {
        if(!v[a[p][i]])
            {
                dfs(a[p][i],a,v);
            }
    }
}

int main()
{ 
ani;
int t1=1;
 // cin>>t1;
while(t1--)
{
    // ll n,k;cin>>n>>k;
    // ll n;cin>>n; ll a[n];rep(i,0,n) cin>>a[i];  


ll n;
cin>>n;
ll k=n/1000;
if(n%1000)
cout<<1000*(k+1)-n<<endl;
else
    cout<<k*1000-n<<endl;











































   

}
return 0;
}

Measured memory_bytes: 3616