#include "bits/stdc++.h" // template by Benq
using namespace std; // Debug template credit: Benq, ramchandra

using ll = long long;
using ld = long double;
using db = double;
using str = string;

using pi = pair<int, int>;
using pl = pair<long long, long long>;
using pd = pair<double, double>;
using pld = pair<long double, long double>;

using vi = vector<int>;
using vd = vector<double>;
using vld = vector<long double>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;
using vpd = vector<pair<double, double>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); }

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define si(s) ((int)(s).size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rs resize
#define ins insert
#define nl "\n"
#define trav(i, x) for(auto& i: x)
#define lower(s) transform(all(s), s.begin(), ::tolower);
#define upper(s) transform(all(s), s.begin(), ::toupper);

const long long INF = 1e18;
const long double PI = acos((long double)-1);
const long long MOD = 998244353;
const int MX = 2e5 + 5;

// INPUT
template<class A> void re(complex<A>& c);
template<class A, class B> void re(pair<A, B>& p);
template<class A> void re(vector<A>& v);
template<class A, size_t SZ> void re(array<A, SZ>& a);
 
template<class T> void re(T& x) { cin >> x; }
void re(double& d) { string t; re(t); d = stod(t); }
void re(long double& d) { string t; re(t); d = stold(t); }
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
 
template<class A> void re(complex<A>& c) { A a, b; re(a, b); c = {a, b}; }
template<class A, class B> void re(pair<A, B>& p) { re(p.first, p.second); }
template<class A> void re(vector<A>& x) { for(auto& i: x) re(i); }
template<class A, size_t SZ> void re(array<A, SZ>& x) { for(auto& i: x) re(i); }

// TO_STRING
#define ts to_string
string ts(char c) { return string(1, c); }
string ts(bool b) { return b ? "true" : "false"; }
string ts(const char* s) { return (string)s; }
string ts(string s) { return s; }
template<class A> string ts(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string ts(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < si(v); ++i) res += char('0' + v[i]);
	res += "}"; return res; }
template<size_t SZ> string ts(bitset<SZ> b) {
	string res = ""; for(int i = 0; i < SZ; ++i) res += char('0' + b[i]);
	return res; }
template<class A, class B> string ts(pair<A,B> p);
template<class T> string ts(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += ts(x);
	}
	res += "}"; return res;
}
template<class A, class B> string ts(pair<A,B> p) {
	return "(" + ts(p.f) + ", " + ts(p.s) + ")"; }
 
// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << ts(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
void EDBG(string names) { names = names; }
template<class H, class... T> void EDBG(string names, H h, T... t) {
	auto pos = names.find(',');
	auto first_name = names.substr(0, pos);
	auto rest = names.substr(pos + 1);
	while(rest.front() == ' '){
		rest = rest.substr(1);
	}
	cerr << "[" << first_name << "]: [" << ts(h) << "]" << nl;
	EDBG(rest, t...);
}

// DEBUG
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define edbg(...) EDBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) 0
#define edbg(...) 0
#endif

// OUTPUT
void pr() {}
template <typename H, typename... T> 
void pr(const H& var1, const T&... var2) {
    cout << var1; 
    pr(var2...); 
}

void ps() { cout << nl; }
template<typename H, typename... T>
void ps(const H& var1, const T&... var2) {
	cout << var1 << ' ';
	ps(var2...);
}

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(20); }
void setIO(string s = "") { unsyncIO(); if(si(s)) { setIn(s + ".in"); setOut(s + ".out"); } }

template<class T> void uni(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)), end(v)); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); } // division of a over b rounded up, assumes b > 0 
ll gcd(ll a, ll b) { while(b) { a %= b; swap(a, b); } return a; }
ll gld(ll a, ll b) { return (a - (a % b)); } // returns the greatest number less than or equal to a and divides b evenly
ll lcm(ll a, ll b) { return (a / (gcd(a, b)) * b); }
ll mpow(ll a, ll b, ll c) { ll res = 1; a %= c; while(b > 0) { if(b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }
ll power(ll a, ll b) { ll res = 1; while(b > 0) { if(b % 2) res = res * a; a = a * a; b >>= 1; } return res; }
// uni: O(nlog(n)), cdiv: O(1), gcd: O(log(min(a, b))), gld: O(1), lcm: O(log(min(a, b))), mpow: O(log(b)), power: O(log(b))



int main() {
	setIO();

	int n;
	re(n);
	//ps(1000 - (n % 1000));
	ll ans = 1000 - (n % 1000);
	if(ans >= 1000) {
		ans -= 1000;
	}
	ps(ans);
}


Measured memory_bytes: 3648