// Name: Kanisht Agarwal Copyright Think before u copy //
//Connect with me at LinkedIn

#include <bits/stdc++.h>
#include <stdint.h>
#include <ext/pb_ds/assoc_container.hpp>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pi 3.1415926535897932
#define nui 100
#define INF 100000000000
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;

/*-------------------------------------------------------------*/
//for (a*b)%mod

uint64_t mulmod(uint64_t a, uint64_t b, uint64_t m)
{
	long double x;
	uint64_t c;
	int64_t r;
	if (a >= m) a %= m;
	if (b >= m) b %= m;
	x = a;
	c = x * b / m;
	r = (int64_t)(a * b - c * m) % (int64_t)m;
	return r < 0 ? r + m : r;
}

/*-------------------------------------------------------------*/

ull binpowmod(ull a, ull b, ull m)
{
	ull res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = ((res % m) * (a % m)) % m;
		}
		a = ((a % m) * (a % m)) % m;
		b >>= 1;
	}
	return res;
}

/*-------------------------------------------------------------*/

ll countsetbits(ll n)
{
	ll count = 0;
	while (n > 0)
	{
		n = n & (n - 1);
		count++;
	}
	return count;
}
/*-------------------------------------------------------------*/
ll sumdigs(ll n)
{
	ll sum = 0;
	while (n > 0)
	{
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

/*-------------------------------------------------------------*/
ll binpow(ll a, ll b)
{
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res *= a;
			res %= 10;
		}
		a *= a;
		a %= 10;
		b >>= 1;
	}
	return res;
}
/*-------------------------------------------------------------*/
void printNcR(ll n, ll r)
{

	ll p = 1, k = 1;

	if (n - r < r)
		r = n - r;

	if (r != 0)
	{
		while (r)
		{
			p *= n;
			k *= r;

			ll m = __gcd(p, k);
			p /= m;
			k /= m;

			n--;
			r--;
		}
	}

	else
		p = 1;

	cout << p << "\n";
}
/*--------------------------------------------------------------*/


/*--------------------------------------------------------------*/
/* Upper bound of x gives numbers less than or equal to x */

ll countdig(ll n)
{
	ll count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}

/*-------------------------------------------------------------*/

bool primech(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;
}

/*----------------------------------------------------------------*/

bool sortbysec(const pair<char, char> &a, const pair<char, char> &b)
{
	return (a.second < b.second);
}

// Sort first part in descending
bool sortinrev(const pair<char, char> &a, const pair<char, char> &b)
{
	return (a.first > b.first);
}

/*-------------------------------------------------------------*/

clock_t time_p = clock();
void TLE()
{
	time_p = clock() - time_p;
	cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

/*-------------------------------------------------------------*/

/*vector<ll>v;
bool prime[10000001]
void seive()
{
	memset(prime,1,sizeof(prime));
	for(ll i=2;i*i<=10000001;i++)
	{
		if(prime[i]==1)
		{
			for(ll j=1;j<=i*i;j+=i)
			{
				prime[j]=0;
			}
		}
	}

} */
/*
ll arr[nui][nui], I[nui][nui];
void mulmat(ll A[][nui], ll B[][nui], ll m)
{
	ll res[m][m];
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			res[i][j] = 0;
			for (ll k = 0; k < m; k++)
			{
				res[i][j] += ((A[i][k]) * (B[k][j]));
			}

		}
	}
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			A[i][j] = res[i][j];
		}
	}
}
ll calpowmat(ll A[][nui], ll m, ll n)
{
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			if (i == j)
			{
				I[i][j] = 1;
			}
			else
			{
				I[i][j] = 0;
			}
		}
	}
	while (n)
	{
		if (n % 2)
		{
			mulmat(I, A, m), n--;
		}
		else
		{
			mulmat(A, A, m), n /= 2;
		}
	}
	for (ll i = 0; i < m; i++)
	{
		for (ll j = 0; j < m; j++)
		{
			A[i][j] = I[i][j];
		}
	}
	return ( A[0][0] +  A[1][0]);


}



/*-------------------------------------------------------------*/
//Adjacency list

vector<ll>adj[100005];

ll vis[100005];  //how many i-th nodes have been visited
void dfs(ll node)
{
	vis[node] = 1;
	for (ll child : adj[node])
	{
		if (!vis[child])
		{
			dfs(child);
		}
	}
}
class tree
{
	vector<ll>parent;
	vector<ll>children;
};



/*Pride,Anger,Jealousy makes people blind.If you think someone knows more than you should never hesitate to ask.*/

//ll dp[101][101];

int main()
{


	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll n;
	cin >> n;
	if (n % 1000)
	{
		cout << 1000 * ((n / 1000) + 1) - n << "\n";
	}
	else
	{
		cout << "0\n";
	}



	return 0;

}



Measured memory_bytes: 6008