/*
 *    author:  rajath_pai
 *    created: 24.07.2020 
*/
//298021OP

#include<bits/stdc++.h>
/*** Functions ***/
#include<algorithm>
#include<functional> // for hash
#include<climits> // all useful constants
#include<cmath>
#include<cstdio>
#include<cstdlib> // random
#include<ctime>
#include<iostream>
#include<sstream>
#include<iomanip> // right justifying std::right and std::setw(width)
/*** Data Structure ***/
#include<deque> // double ended queue
#include<list>
#include<queue> // including priority_queue
#include<stack>
#include<string>
#include<vector>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 


typedef                     long long ll;
typedef                     long long LL;
typedef                     unsigned long long ull;
typedef                     long long          ll;
typedef                     long double        lld;
typedef                     vector<int>        vi;
typedef                     vector<ll>         vll;
typedef                     vector<vi>         vvi;
typedef                     pair<int,int >     pii;
typedef                     vector< pii >      vpii;
typedef                     set<int>           sti;

#define int                 long long
#define pb                  push_back
#define mp                  make_pair
#define ppb                 pop_back
#define sf                  scanf
#define pf                  printf
#define ff                  first
#define ss                  second
#define test                int x;  cin>>x; while(x--)
#define FIO                 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define read()             freopen("input.txt", "r", stdin)
#define write()            freopen("output.txt", "w", stdout)


//FOR
#define fo(i,a,b)           for(int i = a; i < b; i++)
#define foe(i,a,b)          for(int i = a; i <= b; i++)
#define for0(i,n)           for(int i=0; i<n; i++)
#define for1(i,n)           for(int i=1; i<n; i++)
#define forr(i,a,b)         for(int i=a; i>=b; i--)
#define clr(a, n)           memset(a, n, sizeof(a))

//INPUT
#define get1(a)             ll a;cin>>a
#define get2(a,b)           ll a,b;cin>>a>>b
#define get3(a,b,c)         ll a,b,c;cin>>a>>b>>c
#define get4(a,b,c,d)       ll a,b,c,d;cin>>a>>b>>c
#define gets(s)             string s;   cin >> s
#define arrin(x)            for(int i = 0; i < n; i++){ scanf("%d",&x[i]); }
#define arrout(x)           for(int i = 0; i < n; i++){ printf("%d ",x[i]); }
#define SIZE(x)             sizeof(x)/sizeof(x[0]);

//PRINT
#define yes                 printf("yes\n")
#define no                  printf("no\n")
#define Yes                 printf("Yes\n")
#define No                  printf("No\n")
#define YES                 printf("YES\n")
#define NO                  printf("NO\n")
#define puts(s)             cout << s << endl
#define put1(x)             printf("%d\n",x)
#define put2(x, y)          printf("%d %d\n",x,y)
#define put3(x, y, z)       printf("%d %d %d\n",x,y,z)
#define put4(x, y, z, a)    printf("%d %d %d %d\n",x,y,z,a)
#define cspf(i)             printf("Case %d: ", i)

//DEBUG
#define debug1              printf("here\n")
#define debug2              printf("there\n")

#define GCD(m,n)            __gcd(m,n)
#define LCM(m,n)            m*(n/GCD(m,n))
#define C_MAX(a, b)         ((a)>(b)?(a):(b))
#define C_MIN(a, b)         ((a)<(b)?(a):(b))
#define C_ABS(a, b)         ((a)<(b)?(b)-(a):(a)-(b))


#define ALL(a)                      (a).begin(),(a).end()
#define RALL(a)                     (a).rbegin(), (a).rend()
#define SZ(a)                       int((a).size())
#define EACH(i, arr)                for(typeof((arr).begin()) i=(arr).begin(); i!=(arr).end(); ++i)
#define EXIST(str, e)               ((str).find(e)!=(str).end())
#define COUNT(arr, v)               count((arr).begin(), (arr).end(), v)
#define SEARCH(v, w)                search((v).begin(), (v).end(), (w).begin(), (w).end())
#define B_SEARCH(arr, v)            binary_search((arr).begin(), (arr).end(), v)
#define SORT(c)                     sort((c).begin(),(c).end())
#define RSORT(c)                    sort((c).rbegin(),(c).rend())
#define REVERSE(c)                  reverse((c).begin(), (c).end())
#define ROTATE_LEFT(arr, c)         rotate((arr).begin(), (arr).begin()+(c), (arr).end())
#define ROTATE_RIGHT(arr, c)        rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend())
#define SUMI(arr)                   accumulate((arr).begin(), (arr).end(), 0)
#define SUMD(arr)                   accumulate((arr).begin(), (arr).end(), 0.)
#define SUMLL(arr)                  accumulate((arr).begin(), (arr).end(), 0LL)
#define SUMS(arr)                   accumulate((arr).begin(), (arr).end(), string())
#define MULD(arr)                   accumulate((arr).begin(), (arr).end(), 1., multiplies<double>())
#define MULLL(arr)                  accumulate((arr).begin(), (arr).end(), 1LL, multiplies<long long>())
#define UB(arr, n)                  upper_bound((arr).begin(), (arr).end(), n)
#define LB(arr, n)                  lower_bound((arr).begin(), (arr).end(), n)
#define OF_ALL(arr, func)           all_of((arr).begin(), (arr).end(), (func))
#define OF_NONE(arr, func)          none_of((arr).begin(), (arr).end(), (func))
#define OF_ANY(arr, func)           any_of((arr).begin(), (arr).end(), (func))


///CONSTANTS
#define     pi                  acos(-1.0)
#define     ex                  exp(1)


//PRIMES
bool prime(int n)
{
    if (n<2) return false;

    if (n<=3) return true;
    if (!(n%2) || !(n%3)) return false;
    for (int i=5;i*i<=n;i+=6)
    if (!(n%i) || !(n%(i+2))) return false;
    return true;
}

//VOWELS
bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}


//POWER
/*ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
*/
//N^P (mod M)
LL POW_MOD(LL N, LL P, LL M) {
    LL ret = 1;
    while (P > 0) {
        if (P & 1LL) ret = (ret * N) % M;
        N = (N * N) % M;
        P >>= 1LL;
    }
    return ret;
}

// SQUARE
template<class T>
inline T SQR(const T x) { return x * x; }

//nCr
template<typename T>
inline T NCR(T n, T r) {
    if (r > n - r) r = n - r;
    T ans = 1LL;
    for (T i = 0; i < r; i++) {
        ans = ans * (n - i) / (i + 1);
    }
    return ans;
}

//nCr % p  FERMATS LITTLE THEOREM
ll NCR_MOD(ll n, ll r, ll M) {
    if (r > n - r) return NCR_MOD(n, n - r, M);
    ll numerator = 1ll; //numerator
    ll denominator = 1ll; //denominator
    for (ll i = 0; i < r; i++) {
        numerator *= (n - i);
        numerator %= M;
        denominator *= (i + 1);
        denominator %= M;
    }
    return numerator * POW_MOD(denominator, M - 2, M) % M;
}

//clear memory
#define CLR(arr, d) memset((arr), (d),sizeof(arr))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " "  << endl;

// when the number is too large. use powl instead of pow.
// will provide you more accuracy.
// powl(a, b)
// (int)round(p, (1.0/n)) // nth root of p
// to_string(i)         //convert int to string
// stoi( str )          //convert string to int


int32_t main(){
    FIO;
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
}

Measured memory_bytes: 3636