#include <bits/stdc++.h>
	/*#include <ext/pb_ds/assoc_container.hpp> // Common file

	using namespace __gnu_pbds;   //policybased data structures (like set with adttional functionality) some operations 
	//(*name.find_by_order(x) it givesyou value of x index in sorted set and name.find_by_key(no) it gives you the number at index no before sorting)

	typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds_s;


	/* OHH..... BHAI MAARO... MUJHE MAARO.... JO MEIN ISS.. MAADHERCHOD CONTEST MEIN AAYA...*/
	/*Motto  Fuck You Bitch */





	using namespace std;
	#define ull                   unsigned long long	
	#define int64                 __int64
	#define ld                    long double
	#define PI                    3.14159265358979323846264338327950L
	#define substring             s.substr(form_index,to_which_index) //last index is not included
	#define fastio                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define ll                    long long int
	#define deque                 deque<int> d; //dynamic array with push_front() ans pop_front functionality
	#define PQ                    priority_queue<int> p; //max_heap stored data in decresing order
	#define RPQ                   priority_queue<int,vector<int>,greater<int>> p; //min_heap in increasing order
	#define decimalupto(no,y)     fixed<<setprecision(y)<<no
	#define b_to_d(no)            bitset<32> ans("no");ans.to_ullong(); //when you have to make an array of binary array
	#define d_to_b(no,upto)       bitset<upto> ans(no);ans.to_string(); //then you use bitset<int> name.And you can use operations (a&b),(a|b),(a^b)
	#define inf                   1e9+5
	#define mod                   1e9+7//1e9+7	
	#define count1(no)            __builtin_popcountll(no) //tells us the number of setbits means the total no. of 1 in a binary no.
	#define count0_front(no)      __builtin_clz(no)// tells us the number of 0s in a binary no. from begiining
	#define count0_back(no)       __builtin_ctz(no) //tells us the number of 0s from the count0_back
	#define parity(no)            __builtin_parity(no)// tells the number is even or odd by counting the number of 1s 
	#define Erase(i)              myvector.erase (myvector.begin()+i);//erase a specific element from a vector
	#define grp_Erase(i)          myvector.erase (myvector.begin(),myvector.begin()+i); //erase the first i elemnts from a vector
	#define copy array            copy(arr1.begin(), arr1.begin()+n, arr2.begin());
	#define to_uppercase(s)       transform(s.begin(), s.end(), s.begin(), ::toupper);
	#define to_lowercase(s)       transform(s.begin(), s.end(), s.begin(), ::tolower); 
	#define gcd(a,b)              __gcd(a,b)
	#define int_to_string         to_string(i) or string.push_back(arr[i]+'0')
	#define string_to_int         s[i]-'a'
	#define dbg(x) cout << '>' << #x << ':' << x << endl;

	ll power(ll x,ll y,ll md=mod){
		ll res = 1;
		res%=md;
		while(y>0){
			if(y&1)res = (res*x)%md;
				x *= x;
				 if(x>=md) x %= md; y >>= 1;
				}
				return res;
		}


 //  ll power(ll n, ll p){  
 //  	ll ans=1;
 //  	while(p>0){
 //  		if(p%2==1) ans=(ans*p)%mod;
 //  		n=(n*n)%mod;
 //  		p/=2;
 //  	}
 // }
 

	int main(){	
	// #ifndef ONLINE_JUDGE
	//    freopen("input.txt","r",stdin); // round(n/2.0) round upto the upcoming even no .ex(round(5/2.0)) gives 3 because 6 is the upcoming even no
	//    freopen("output.txt","w",stdout);
	// #endi
		fastio
		int n;
		cin>>n;
		if(n%1000==0){
			cout<<0<<"\n";
			return 0;
		}
		if(n<1000){
			cout<<1000-n<<"\n";
			return 0;
		}
		int ans=0;
		while(ans<n){
			ans+=1000;
		}
		cout<<abs(ans-n);
		
		//cout<<n<<"\n";
		
       
}

Measured memory_bytes: 3616