#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define MOD 1000000007
    #define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
    #define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
    //    for(auto& it : m)
    void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
    //  priority_queue<ll int> pq;
    //  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
    //  vector<ll int> v;
    //  vector< pair<ll int,ll int> > v;
    //  set<ll int>::iterator it=s.begin();
    //  unordered_map<  pair<ll int,ll int>, ll int> mp;
     
     
     
    ll int power(ll int x, ll int y, ll int p)  
    {  
        ll int res = 1;     // Initialize result  
      
        x = x % p; // Update x if it is more than or  
                    // equal to p 
       
        if (x == 0) return 0; // In case x is divisible by p; 
      
        while (y > 0)  
        {  
            // If y is odd, multiply x with result  
            if (y & 1)  
                res = (res*x) % p;  
      
            // y must be even now  
            y = y>>1; // y = y/2  
            x = (x*x) % p;  
        }  
        return res;  
    }  
     
    void computeLPSArray(string pat, int M, int* lps) 
    { 
        // length of the previous longest prefix suffix 
        int len = 0; 
      
        lps[0] = 0; // lps[0] is always 0 
      
        // the loop calculates lps[i] for i = 1 to M-1 
        int i = 1; 
        while (i < M) { 
            if (pat[i] == pat[len]) { 
                len++; 
                lps[i] = len; 
                i++; 
            } 
            else // (pat[i] != pat[len]) 
            { 
                // This is tricky. Consider the example. 
                // AAACAAAA and i = 7. The idea is similar 
                // to search step. 
                if (len != 0) { 
                    len = lps[len - 1]; 
      
                    // Also, note that we do not increment 
                    // i here 
                } 
                else // if (len == 0) 
                { 
                    lps[i] = 0; 
                    i++; 
                } 
            } 
        } 
    }
    bool subset[10005][1005]; 
    void isSubsetSum(ll int set[],ll int n,ll int sum) 
{ 
    // The value of subset[i][j] will be true if 
    // there is a subset of set[0..j-1] with sum 
    // equal to i 
    
  
    // If sum is 0, then answer is true 
    
  
    // If sum is not 0 and set is empty, 
    // then answer is false 
    
  for (int i = 0; i <= n; i++) 
        subset[i][0] = true; for (int i = 1; i <= sum; i++) 
        subset[0][i] = false; 
    // Fill the subset table in botton up manner 
    for (int i = 1; i <= n; i++) { 
        for (int j = 1; j <= sum; j++) { 
            if (j < set[i - 1]) 
                subset[i][j] = subset[i - 1][j]; 
            if (j >= set[i - 1]) 
                subset[i][j] = subset[i - 1][j] 
                               || subset[i - 1][j - set[i - 1]]; 
        } 
    } 
  
    /*   // uncomment this code to print table 
     for (int i = 0; i <= n; i++) 
     { 
       for (int j = 0; j <= sum; j++) 
          printf ("%4d", subset[i][j]); 
       printf("\n"); 
     }*/
  
   
} 
     
    int main()
    {
      fastio();
      
    ll int T;
    T=1;
   

    while(T--)
    { 

        ll int n;
        cin>>n;
        n=1000-n%1000;
        if(n==1000)n=0;
        cout<<n<<endl;
   }
     
        
      
     
     
     
        return 0;
    }

Measured memory_bytes: 3644