#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>

#define MOD 1000000007
#define debug(x) cout<<"x :"<<x<<endl;
//#define case(t,ans) cout<<"Case #"<<t<<": "<<ans<<endl;
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define for_it(it,s) for (auto it = s.begin(); it != s.end(); it++)
#define for_each(r,s) for(auto r:s)

#define all(s) s.begin(),s.end()
#define rall(s) s.end(),s.begin()
#define F first
#define S second
#define PB push_back
#define pb pop_back
#define EB emplace_back
#define pf push_front

#define fill0(arr) memset(arr,0,sizeof(arr))
#define filln(arr) memset(arr,-1,sizeof(arr))
#define MP make_pair
#define vi vector<int>
#define vll vector<ll>
#define vf vector<float>
#define vd vector<ld>
#define precision(x) cout<<fixed<<setprecision((x));
 


#define pi pair<int,int> 
#define ll long long 
#define ld long double
#define endl "\n"
//typedef long long ll;
//typedef vector<int> vi;
//typedef pair<int,int> pi;
//sort(a, a+n);
//reverse(a, a+n);
//random_shuffle(a, a+n);

const ll mod=1e9 + 7;
const ll mod1=998244353;



# define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";


#define case(i) cout<<"Case "<<i<<": ";



//using namespace boost::multiprecision;
using namespace std;


// TC;-  O(log(min(a,b))) SC;-O(1)
long long gcd (long long  a, long long b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

// TC;-  O(log(min(a,b))) SC;-O(1)
ll lcm (ll a, ll b) {
    return a / gcd(a, b) * b;
} 


// TC :- O(log(n)) SC;-O(1)
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


// TC :- O(log(n)) SC;-O(1)       modulo binpow
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int C(int n, int k) {
    double res = 1;
    for (int i = 1; i <= k; ++i)
        res = res * (n - k + i) / i;
    return (int)(res + 0.01);
}

//  TC;-O(plogpn)
int factmod(int n, int p) {
    int res = 1;
    while (n > 1) {
        res = (res * ((n/p) % 2 ?  p-1 : 1)) % p;
        for (int i = 2; i <= n%p; ++i)
            res = (res * i) % p;
        n /= p;
    }
    return res % p;
}

// TC: O(n) SC:O(1)
bool isPalindrome(string s)
{
    ll l=s.length();
    for(int i=0;i<l/2;i++)
    {
        if(s[i]!=s[l-i-1])
        {
            return false;
        }
    }
    return true;
}

string prefix_function(string s) {
    int n = (int)s.length();
    string piiii;
    for (int i = 0; i < n; i++)
        for (int k = 0; k <= i; k++)
            if (s.substr(0, k) == s.substr(i-k+1, k))
                piiii.push_back(k);
    return piiii;
}

long long computeXOR(long long  n) 
{ 
    // Modulus operator are expensive on most of the  
    // computers. n & 3 will be equivalent to n % 4.    
  
    switch(n & 3) // n % 4  
    { 
    case 0: return n;     // if n is multiple of 4 
    case 1: return 1;     // If n % 4 gives remainder 1   
    case 2: return n + 1; // If n % 4 gives remainder 2     
    case 3: return 0;     // If n % 4 gives remainder 3   
    } 
    return -1;
} 
  
bool isPrime(int n)
{
    for(int i=2;i*i<n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
    }
    return true;
}
void solve();
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    clock_t launch=clock();
    for(ll i=1;i<=t;i++)
    {
       // case(i);
        solve();
    }
  
  
     clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
     cerr<<"error is good"<<endl;
    return 0;
}



void solve()
{
    int t = 1;
   // cin>>t;
    
    while(t--)
    {
       int n;
       cin >> n;
      // cout << n % 1000 << endl;
       if(n % 1000 == 0) cout << 0 << endl;
       else
       cout << 1000 - (n % 1000) <<endl; 
    }
}




Measured memory_bytes: 3704