#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
 
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
typedef vector < pii > vpii;
typedef vector < pll > vpll;
 
typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
#define fl(i, a, b)    for (int i(a); i <= (b); i ++)
#define rep(i, n)        fl (i, 1, (n))
#define loop(i, n)        fl (i, 0, (n) - 1)
#define rfl(i, a, b)    for (int i(a); i >= (b); i --)
#define rrep(i, n)        rfl (i, (n), 1)
 
#define all(v)     (v).begin(), (v).end()
#define srt(v)    sort (all (v))
 
#define pb push_back
#define mp make_pair
 
#define sz(x) ((int) (x).size())
#define fill (x, y)    memset(x, y, sizeof(x))
#define clr(a)    fill(a, 0)
// #define endl '\n'
 
#define PI 3.14159265358979323
 
const int Maxn = 1e6 + 1;
const int Mod = 1e9 + 7;
 
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
 
const ll MOD = 1000000007LL;
const ll MAX = 100010LL;
 
template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b);}
template <typename T> T power(T x, T y, ll m = MOD) { T ans = 1; x %= m; while (y > 0) { if (y & 1ll) ans = (ans * x) % m; y >>= 1ll; x = (x * x)%m; } return ans%m;}
 
template<typename T, typename T1>
T mod(T x, T1 p) {
    x %= p;
    if (x < 0)
        x += p;
    return x;
}
 
void leastPrimeFactor(vector<int>&least_prime, int n) 
{ 
    least_prime[1] = 1;  
    for (int i = 2; i <= n; i++) 
    { 
        if (least_prime[i] == 0) 
        { 
            least_prime[i] = i; 
            for (int j = 2*i; j <= n; j += i) 
                if (least_prime[j] == 0) 
                   least_prime[j] = i; 
        } 
    } 
}
 
 
// int inv[Maxn], ifact[Maxn], fact[Maxn];
// template<typename T>
// T inverse(T x, T p) 
// {
//     x = mod(x, p);
//     if (x == 1)
//         return x;
//     return mod((1LL * (-p / x) * (inv[p % x] % p)) , p); 
//     // Since inverse of p % x is already calculated.
// }
 
 
// ll NcR(ll n, ll r) 
// {
//     int ret = (1LL * ifact[n - r] * ifact[r]) % Mod ;
//  ret = (1LL * ret * fact[n]) % Mod;
//     return ret;
// }
 
 
// int n, t[4*MAXN];
// void build(int a[], int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = t[v*2] + t[v*2+1];
//     }
// }
// int sum(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return sum(v*2, tl, tm, l, min(r, tm))
//            + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
// }
// void update(int v, int tl, int tr, int pos, int new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = t[v*2] + t[v*2+1];
//     }
// }

void dfs(int l, vector<int>&vis, vector<vector<int> > &adj, int dis)
{
    vis[l] = dis;
    for(int &ne:adj[l])
        if(!vis[ne])
            dfs(ne, vis, adj, dis+1);
}

int main() 
{
    FAST_IO;
    // int nt;
    // cin >> nt;
    // // vvi dir = {{-1,0},{1,0},{0,1},{0,-1}};
    // for(int ze = 0 ; ze < nt ; ze++)
    // {

    int n;
    cin >> n;
    cout << (1000-n%1000)%1000 << endl;
        
    // }
}

Measured memory_bytes: 3644