#include <random>
#include <cmath>
#include <unordered_map>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <unordered_set>
#include <array>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <numeric>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db; 
#define ut uint64_t
#define ar array
struct fhash{
    static ut si(ut x) {
        x+=0x9e3779b97f4a7c15;
        x=(x^(x>>30))*0xbf58476d1ce4e5b9;
        x=(x^(x>>27))*0x94d049bb133111eb;
        return x^(x>>31); }
    size_t operator()(ut x) const {
        static const ut fr = chrono::steady_clock::now().time_since_epoch().count();
        return si(x+fr);}
  };
//DEFINES 
#define fe first
#define se second
#define pb push_back
#define mp make_pair
#define pob pop_back()
#define sz(v) ((int)(v).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 

#define forn(i, n) for (int i=0;i<(int)(n);++i)
#define for1(i, n) for (int i=1;i<=(int)(n);++i)
#define ford(i, n) for (int i=(int)(n)-1;~i;--i)
#define fore(i, a, b) for (int i=(int)(a);i<=(int)(b); ++i)
#define trav(a,x) for (auto& a: x)
#define trav0(i,m) for(auto i = (m).begin();i!=(m).end();i++)
//TYPEDEFS
typedef long long ll;
typedef long double ld;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl; 
typedef pair<db,db> pd; 

typedef vector<int> vl;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<db> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
//TO STRINGS 
#define ts to_string 
string ts(char c) { return string(1,c); }
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 to_string(vector<bool> v) { 
	string res = "{"; forn(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string ts(bitset<SZ> b) {
	string res = ""; forn(i,SZ) 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.fe)+", "+ts(p.se)+")"; }
//TEMPLATES 
template<class T> bool chmin(T& a, const T& b) {  
  return b < a ? a = b, 1 : 0; }
template<class T> bool chmax(T& a, const T& b) { 
  return a < b ? a = b, 1 : 0; } 
template<class T> bool ptwo(T a) { 
  return a && (!(a&(a-1)));}
template<class T> void remdup(vector<T>& v) {  
  sort(all(v)); v.erase(unique(all(v)),end(v)); }

ll gcd(ll a,ll b) {  return b?gcd(b,a%b):a;} 
template<class T>bool prime(T n){
  for(T i=2;i*i<=n;i++) if(n%i==0)return 0;return 1;}

vl split(string s){ vl v; stringstream ss(s); 
  for (int i; ss >> i;) { v.pb(i); 
  if (ss.peek() == ',') ss.ignore(); } return v; }
//BITS
ll mask(int i){ return (ll(1)<<i)-1;}
int pct(signed x) { return __builtin_popcount(x); }
int pct(ll t){return __builtin_popcountll(t);}
int bits(signed x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
int bits(ll t){ return 63-__builtin_clzll(t); }

#define cb(n, b)(((n)>>(b))&1) 
#define sb(n, b)((n)|(static_cast<decay<decltype(n)>::type>(1)<<(b)))
#define rb(n, b)((n)&~(static_cast<decay<decltype(n)>::type>(1)<<(b))) 
#define fb(n, b)((n)^(static_cast<decay<decltype(n)>::type>(1)<<(b)))
//INPUT
template<class T> void re(T& x) { cin >> x; }//vpi,vl,vi
void re(double& d) { string t; re(t); d = stod(t); }
void re(ld& 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, class B> void re(pair<A,B>& p) { re(p.fe,p.se); }
template<class A> void re(vector<A>& x) { trav(a,x) re(a); }
template<class A, size_t SZ> void re(ar<A,SZ>& x) { trav(a,x) re(a); }
//OUTPUT
template<class A> void pr(A x) { cout << ts(x); } //vpi,mp,set<pi>
template<class H, class... T> void pr(const H& h, const T&... t) { 
	pr(h); pr(t...); }
void ps() { pr("\n"); } // print w/ spaces
template<class H, class... T> void ps(const H& h, const T&... t) { 
	pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

//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...); }

const int MOD = 1e9+7; // 998244353;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int dx[2][4] = {{-1, 1, 0, 0},{1,-1,-1,1}};  
const int dy[2][4] = {{0, 0, -1, 1},{1,1,-1,-1}};  

void IOS(int n){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.precision(n); cout << fixed;}


mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 

const int MXN = 2e5+5;

void solve(){ 
    int n; re(n);
    ps((1000-n%1000)%1000);
}
int main(){ 
    IOS(10);
    int t=1; //re(t);
    for1(i,t) solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

Measured memory_bytes: 3260