#include <bits/stdc++.h>
using namespace std;

/* useful defines with short names */
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()

/* useful typedefs with short names */
typedef long long	ll;
typedef double 	db;
typedef long double ldb;
typedef complex<db> cd;

typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef pair<db, db>	pdb;
typedef pair<ldb, ldb>	pldb;
typedef pair<int, ll>	pil;
typedef pair<ll, int>	pli;

typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<string>	vs;
typedef vector<char>	vc;
typedef vector<db>		vdb;
typedef vector<ldb>		vldb;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<pdb>		vpdb;
typedef vector<pldb>	vpldb;
typedef vector<pil>		vpil;
typedef vector<pli>		vpli;

/* modular arithmetic class implementation */
template<int MOD = 1'000'000'007>
struct Modular
{
	int value;
	static const int MOD_VAL = MOD;
	
	Modular(ll v = 0) { value = v % MOD; if (value < 0) value += MOD; }
	Modular(ll a, ll b) : value(0) { *this += a; *this /= b; }

	Modular& operator+=(const Modular& o) { value += o.value; if (value >= MOD) value -= MOD; return *this; }
	Modular& operator-=(const Modular& o) { value -= o.value; if (value < 0) value += MOD; return *this; }
	Modular& operator*=(const Modular& o) { value = (ll)value * o.value % MOD; return *this; }
	Modular& operator/=(const Modular& o) { return *this *= o.inv(); }
	Modular& operator++() { return *this += 1; }
	Modular& operator--() { return *this -= 1; }
	
	Modular exp(Modular a, ll k)
	{
		Modular res = 1;
		while (k) { if (k & 1LL) res *= a; a *= a; k >>= 1; }
		return res;
	}

	Modular inv() { return exp(value, MOD - 2); }
	
	friend Modular operator+(const Modular& a, const Modular& b) { return a += b; }
	friend Modular operator-(const Modular& a, const Modular& b) { return a -= b; }
	friend Modular operator-(const Modular& a) { return 0 - a; }
	friend Modular operator*(const Modular& a, const Modular& b) { return a *= b; }
	friend Modular operator/(const Modular& a, const Modular& b) { return a /= b; }

	friend ostream& operator<<(ostream& os, const Modular& m) { os << m.value; return os; }
	operator int() { return value; }

	bool operator==(const Modular& o) { return value == o.value; }
	bool operator!=(const Modular& o) { return value != o.value; }
};

typedef Modular<> mod;

/* scanf with template */
template<typename T> T scanf_t();

/* scanf template specializations */
template<>  int            scanf_t();
template<>  ll             scanf_t();
template<>  db             scanf_t();
template<>  ldb            scanf_t();
template<>  char           scanf_t();
template<>  float          scanf_t();
string      scanf_t(int);  

/* short names for scanf template specializations */
int     (*si)()     =  scanf_t<int>;
ll      (*sl)()     =  scanf_t<ll>;
db      (*sdb)()    =  scanf_t<db>;
ldb     (*sldb)()   =  scanf_t<ldb>;
char    (*sc)()     =  scanf_t<char>;
float   (*sf)()     =  scanf_t<float>;
string  (*ss)(int)  =  scanf_t;

/* printf template functions */
template<typename T> void printf_t(const T&, char='\n');
template<typename T> void printf_t(const T*, char='\n');
template<typename T> void printf_t(T*, char='\n');
template<typename T, typename Alloc, template<typename, typename> class Container>
void printf_t(const Container<T, Alloc>&, char='\n');

/* varadic print that uses printf */
template<typename T> void print(const T&);
template<typename T, typename... Args> void print(const T&, const Args&...);

/* read to array from standard input with scanf */
template<typename It> void in(It, int);
/* read to standard C++ container with scanf and push_back */
template<typename T, typename Alloc, template<typename, typename> class Container>
void sv(Container<T, Alloc>&, int);

/* write an array to standard output */
template<typename It> void out(It, It, char='\n', char=' ');
/* write standard C++ container to standard output */
template<typename Container> void pv(const Container&, char='\n', char=' ');

/* short names for printf template specializations */
void pi(const int&, char='\n');
void pl(const ll&, char='\n');
void pd(const db&, char='\n');
void pld(const ldb&, char='\n');
void pf(const float&, char='\n');
void pc(const char&, char='\n');
void ps(const string&, char='\n');

/* useful, general purpose algorithms */
ll russian(ll, ll, ll);
ll fastpow(ll, ll, ll);
ll slowpow(ll, ll, ll);
ll extgcd(ll, ll);
ll _gcd(ll, ll);
ll _lcm(ll, ll);
ll _inv(ll, ll);

/* useful constants */
const  int  INF   =  1e9;
const  ll   LINF  =  1e18;
const  ll   M     =  1e9 + 7;

int main()
{
	int n = si();
	int a = n % 1000;
	print((1000 - a) % 1000);

	return 0;
}

/* scanf template specilizations */
template<> int scanf_t() { int x; scanf("%d", &x); return x; }
template<> ll scanf_t() { ll x; scanf("%lld", &x); return x; }
template<> db scanf_t() { db x; scanf("%lf", &x); return x; }
template<> ldb scanf_t() { ldb x; scanf("%Lf", &x); return x; }
template<> char scanf_t() { char x; scanf(" %c", &x); return x; }
template<> float scanf_t() { float x; scanf("%f", &x); return x; }
string scanf_t(int n) { char x[n + 7]; scanf("%s", x); return string(x); }

/* printf template specilizations */
template<> void printf_t(const int& x, char end) { printf("%d%c", x, end); }
template<> void printf_t(const ll& x, char end) { printf("%lld%c", x, end); }
template<> void printf_t(const db& x, char end) { printf("%.8lf%c", x, end); }
template<> void printf_t(const ldb& x, char end) { printf("%.10Lf%c", x, end); }
template<> void printf_t(const float& x, char end) { printf("%f%c", x, end); }
template<> void printf_t(const char& x, char end) { printf("%c%c", x, end); }
template<> void printf_t(const string& x, char end) { printf("%s%c", x.c_str(), end); }
template<> void printf_t(const char* x, char end) { printf("%s%c", x, end); }
template<> void printf_t(char* x, char end) { printf("%s%c", x, end); }
template<> void printf_t(const mod& x, char end) { printf_t(x.value, end); }
template<> void printf_t(const size_t& x, char end) { printf("%lu%c", x, end); }
template<> void printf_t(const ssize_t& x, char end) { printf("%ld%c", x, end); }
template<typename T, typename Alloc, template<typename, typename> class Container>
void printf_t(const Container<T, Alloc>& v, char end) { pv(v, end); }

/* variadic print base case */
template<typename T> void print(const T& last) { printf_t(last); }

/* variadic print */
template<typename T, typename... Args>
void print(const T& first, const Args&... rest)
{
	printf_t(first, ' ');
	print(rest...);
}

/* scanf n variables of type T */
template<typename T>
void in(T* begin, int n)
{
	while (n--)
		*begin++ = scanf_t<T>();
}

/* scanf n variables of type T to standard C++ container and push them back */
template<typename T, typename Alloc, template<typename, typename> class Container>
void sv(Container<T, Alloc>& v, int n)
{
	auto it = std::back_inserter(v);
	while (n--)
		*it = scanf_t<T>();
}

/* printf array to standard output */
template<typename It>
void out(It begin, It end, char endl, char sep)
{
	if (begin == end)
	{
		printf("%c", endl);
		return;
	}	
	while (next(begin) != end)
		printf_t(*begin++, sep);
	printf_t(*begin, endl);
}

/* printf standard C++ container to standard output */
template<typename Container>
void pv(const Container& v, char end, char sep) { out(all(v), end, sep); }

/* implementation short named functions for template specializations */
void  pi(const   int&     x, char end)  {  printf_t(x, end);  }
void  pl(const   ll&      x, char end)  {  printf_t(x, end);  }
void  pd(const   db&      x, char end)  {  printf_t(x, end);  }
void  pld(const  ldb&     x, char end)  {  printf_t(x, end);  }
void  pf(const   float&   x, char end)  {  printf_t(x, end);  }
void  pc(const   char&    x, char end)  {  printf_t(x, end);  }
void  ps(const   string&  x, char end)  {  printf_t(x, end);  }

/* russian peasants algorithm */
ll russian(ll a, ll k, ll m)
{
	ll res = 0LL;
	while (k)
	{
		if (k & 1LL)
			res = (res + a) % m;
		a = (a + a) % m;
	}
	return res;
}

/* fast power - a^k % m */
ll fastpow(ll a, ll k, ll m)
{
	ll res = 1LL;
	while (k)
	{
		if (k & 1LL)
			res = (res * a) % m;
		a = (a * a) % m;
		k >>= 1;
	}
	return res;
}

/* fast power with russian peasants algorithm */
ll slowpow(ll a, ll k, ll m)
{
	ll res = 1LL;
	while (k)
	{
		if (k & 1LL)
			res = russian(res, a, m);
		a = russian(a, a, m);
		k >>= 1;	
	}
	return res;
}

/* greatest common divisor of a and b */
ll _gcd(ll a, ll b)
{
	while (b)
		swap(a %= b, b);
	return a;
}

/* least common multiple of a and b */
ll _lcm(ll a, ll b)
{
	return a / _gcd(a, b) * b;
}

/* calculate inverse of a modulo */
ll _inv(ll a, ll p)
{
	return fastpow(a, p - 2, p);
}

/* extended Eucilean algorithm implementation - calculate a * k + b * l = GCD(a, b) */
ll extgcd(ll a, ll b, ll& k, ll& l)
{
	if (b == 0)
	{
		k = 1; l = 0;
		return a;
	}
	ll res = extgcd(b, a % b, l, k);
	l -= a / b * k;
	return res;
}


Measured memory_bytes: 3832