/**

author:	©LoneWolfDON
Git: MahinHossainMunna

**/
/*

*/
///...................................template starts.................................................///

/// headers ///

#include                        <bits/stdc++.h>
#include                        <climits>

///defined ///

#define     ll                  long long
#define     inf                 999999999
#define     MAX                 1000001
#define     fastIO;             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define     pb                  push_back
#define     endl                '\n'
#define     OJ()                ll tc; cin>>tc; while(tc--)

///Read-Write///
#define	    READ;               freopen("input.txt","r",stdin);
#define     WRITE;              freopen("output.txt","w",stdout);

/// loops ///

#define fo(i,a,m)               for(ll i = a ; i < m ; i++)
#define refor(i,a,m)            for(ll i = a ; i > m ; i--)
#define foreq(i,a,m)            for(ll i = a ; i <= m ; i++)
#define revforeq(i,a,m)         for(ll i = a ; i >= m ; i--)

using namespace std;

///....................................................................................///

ll power(ll x,ll y)
{
    if (y == 0)
    return 1;
    ll p = power(x, y/2);
    p = (p * p);

    return (y%2 == 0)? p : (x * p);
}
///....................................................................................///

int lcm(ll a, ll b)
{
    ll lar = max(a, b);
    ll small = min(a, b);
    for (ll i = lar; ; i += lar)
    {
    if (i % small == 0)
        return i;
    }
}
///....................................................................................///

int gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
///....................................................................................///

int bsearch(ll arr[],ll l,ll r,ll x)
{
    while (l <= r)
    {
    ll m = l + (r - l) / 2;
    if (arr[m] == x)
    {
        return m;
    }
    if (arr[m] < x)
    {
        l = m + 1;
    }
    else
        r = m - 1;
    }
    return -1;
}

///....................................................................................///

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

///....................................................................................///
struct cmp
{
        bool operator()(const int a, const int b)
        {
                return a > b;
        }
};

///....................................................................................///

void bfs(vector<ll>g[],ll dist[],bool v[],ll u)
{
    queue<ll> q;

    q.push(u);
    v[u] = true;
    dist[u]=0;

    while (!q.empty())
    {
        ll f = q.front();
        q.pop();

        // Enqueue all adjacent of f and mark them visited
        for (auto i = g[f].begin(); i != g[f].end(); i++)
        {
            if (!v[*i])
            {
                q.push(*i);
                v[*i] = true;
                dist[*i]=dist[f]+1;
            }
        }
    }
}

///....................................................................................///

void dfs(ll source,ll visited[],vector<ll>graph[],ll l)
{
    visited[source]=l;
    ll i;

    for(i=0;i<graph[source].size();i++)
    {
        if(visited[graph[source][i]]==-1)
            dfs(graph[source][i], visited, graph, l);
    }
}

///....................................................................................///

bool isPerfectSquare(long double x)
{

  long double sr = sqrt(x);

  return ((sr - floor(sr)) == 0);
}

///...................................template ends.................................................///

int main()
{
	fastIO;

    ll n;
    cin>> n;

    if(n%1000 == 0)
    cout<<0<<endl;

    else
    {
        ll div =0 , rem = 0;
        div = ceil(n/1000.0);
        rem = n - div*1000;
        cout<<abs(rem)<<endl;
    }

}


Measured memory_bytes: 3736