#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
//2^8 works in 2 sec but make sure to see the size
//2^7 works with 2 arrray of size of 2^7 but not three
//(5*n^2 + 4,5*n^2 - 4) is a prefect square then the number if fibonaci
//check if multiple of 6 gives the prime number
//i think one mutiple gives one prime and the other gives one prime
//log(log(n)) approx. number of distinct prime factors for most number
//pn > nlogn pn is nth prime number //here base is 10
//sum of binomial coefficient is 2^n + 1
 
 
using ll = long long;
 
int main() {
	int n;
	cin >> n;
	int w = n / 1000;
	if (n % 1000 != 0) {
		w++;
	}
	cout << w * 1000 - n;
}
















//#pragma GCC optimize("Ofast")

// #include <bits/stdc++.h>
//#include <iostream>  // * Header that defines the standard input/output stream objects: [ cin, cout, cerr ]
//#include <iomanip>   // * iomanip is a library that is used to manipulate the output of C++ program. [set_precision, set_time]
//#include <cassert>   // * C Diagnostics Library -> assert.h defines one macro function that can be used as a standard debugging tool :
//#include <cmath>     // * Header <cmath> declares a set of functions to compute common mathematical operations and transformations. Link: http://www.cplusplus.com/reference/cmath/
//#include <cstdio>    // * Streams are handled in the cstdio library as pointers to FILE objects.
//#include <cstring>   // * This header file defines several functions to manipulate C strings and arrays. Link: http://www.cplusplus.com/reference/cstring/
//#include <cstdlib>   // * This header defines several general purpose functions, including dynamic memory management, random number generation, communication with the environment, integer arithmetics, searching, sorting and converting. Link : http://www.cplusplus.com/reference/cstdlib/
//#include <map>       // * Header that defines the map and multimap container classes. Maps are typically implemented as BST. binary search trees.
//#include <set>       // * Sets are typically implemented as binary search trees.
//#include <stack>     // * template <class T, class Container = deque<T> > class stack;
//#include <queue>     // * Link : https://en.cppreference.com/w/cpp/header/queue
//#include <vector>    // * Constructs a vector, initializing its contents depending on the constructor version used.
//#include <chrono>    // * The chrono library defines three main types as well as utility functions and common typedefs. clock, time points, durations.
//#include <algorithm> // * The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements. Link : http://www.cplusplus.com/reference/algorithm/
//#include <unordered_map>
//#include <unordered_set>

//using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
// Link : https://codeforces.com/blog/entry/11080
//template <typename T>
//using ordered_set = tree<
    //T,
    //null_type,
    //less<T>,
    //rb_tree_tag,
    //tree_order_statistics_node_update>;
// ! order_of_key(x) : returns the number of values less than x
// ! find_by_order(k) : returns the iterator to kth largest element. (0-based)

/*
    ! stuff you should look for
        * int overflow, array bounds
        * special cases (n=1)?
        * boundary cases
        * do something instead of nothing and stay organized.
        # BELIEVE in yourself.
*/
/*
? Some basic stuff that you should learn:

        ? Sets : Unique element container.
            ! set<int,greater<int> > s; // to order the set in descending order
            * To check if an element is in a set : s.count(x)
            ! Another method to check if an element exists in a set :if(s.find(x)!=s.end()){ // condition  }
            * Value of First Element of Set : *(s.begin())
            * Value of Last Element of Set : *(--s.end())
            ! To erase an element by value: s.erase(x);
            * begin() - returns an iterator to first element of set. The value of the element can be accessed using *(s.begin())
            * end() - Returns an iterator to the theoretical element that follows last element in the set.
            * size() - Returns the number of elements in the set.
            * max_size() - Returns the maximum number of elements that the set can hold.
            * empty() - Returns whether the set is empty.
            ! find(x) - Returns an iterator to the element ‘x’ in the set if found, else returns the iterator to end.
            * erase(x)– Removes the value ‘x’ from the set. It erases an element by value
            * count(x) - Returns 1 or 0 based on the element ‘x’ is present in the set or not. It's the best way to check for the presence of an element.
            * lower_bound(x) – Returns an iterator to the first element that is equivalent to ‘x’ or definitely will not go before the element ‘x’ in the set.
            lower_bound can also be thought as the smallest element greater than or equal to x
            * Return reverse iterator to reverse beginning: (s.rbegin())
            * Set to be sorted in decreasing order: set<int, greater<int> >
            * emplace() : If the function successfully inserts the element (because no
                    equivalent element existed already in the set), the function returns a
                    pair of an iterator to the newly inserted element and a value of true.
            * const bool is_in = s.find(x) != s.end(); check if an element is in the set.
            ! myset.erase(x) #directly by value. logarithmic complexity
            ! myset.erase(iteratortoanelement,s.end())
            * for_each(all(s),do_something);
            ! set<int> :: iterator it = myset.find(60);

        ? Vectors
            @ Erase elemnents by value rather than position
            # vec.erase(std::remove(vec.begin(), vec.end(), 8), vec.end());
            *
            @ Erase duplicates in a sorted array
            # v.erase(unique(v.begin(), v.end()), v.end());
            *
            @ Erase elements by position
            # vec.erase(vec.begin() + 1);
            vector<int> v; v.resize(n,0); // resizes the vector and initializes it too.
            front(), back(), push_back(), pop_back()
            * begin() - Returns an iterator pointing to the first element in the vector
            * end() - Returns an iterator pointing to the theoretical element that follows the last element in the vector
            * rbegin() - Returns a reverse iterator pointing to the last element in the vector (reverse beginning).
            * rend() - Returns a reverse iterator pointing to the theoretical element preceding the first element in the vector
            * cbegin(),cend(),crbegin(),crend()
            * size() - Returns the number of elements in the vector.
            * max_size() -  Returns the maximum number of elements that the vector can hold.
            * capacity() - Returns the size of the storage space currently allocated to the vector expressed as number of elements.
            * resize() - Resizes the container so that it contains ‘n’ elements.
            * empty() - Returns whether the container is empty.
            * shrink_to_fit() - Reduces the capacity of the container to fit its size and destroys all elements beyond the capacity.
            * reserve() - Requests that the vector capacity be at least enough to contain n elements.
            * [i] - Returns a reference to the element at position ‘i’ in the vector
            * at(i) - Returns a reference to the element at position ‘i’ in the vector
            # front() - Returns a reference to the first element in the vector
            # back() - Returns a reference to the last element in the vector
            * data() - Returns a direct pointer to the memory array used internally by the vector to store its owned elements.
            * assign() - It assigns new value to the vector elements by replacing old ones
            * push_back() - It push the elements into a vector from the back
            # pop_back() - It is used to pop or remove elements from a vector from the back.
            ! insert() - It inserts new elements before the element at the specified position
            * erase() - It is used to remove elements from a container from the specified position or range
            * swap() - It is used to swap the contents of one vector with another vector of same type. Sizes may differ.
            * clear() - It is used to remove all the elements of the vector container
            * emplace() - It extends the container by inserting new element at position
            * emplace_back() - It is used to insert a new element into the vector container, the new element is added to the end of the vector
            # for (auto it = myvector.begin(); it != myvector.end(); ++it)  // normal iterator
            # for (auto t:v)

        ? Queue
            * empty() - Returns whether the queue is empty.
            * size() - Returns the size of the queue.
            * emplace() - Insert a new element into the queue container, the new element is added to the end of the queue.
            * front() - front() function returns a reference to the first element of the queue.
            * back() - returns a reference to the last element of the queue.
            * push(x) - adds the element ‘x’ at the end of the queue
            * pop() - deletes the first element of the queue

        ? Priority_Queue
            ! priority_queue <int, vector<int>, greater<int>> pq; // to make a priority queue in descending order
            * empty() - returns whether the queue is empty.
            * size() -  returns the size of the queue.
            # top() -  Returns a reference to the top most element of the queue
            * push(x) - adds the element ‘x’ at the end of the queue.
            * pop() -  deletes the first element of the queue.
            * swap() -  swap the contents of one priority queue with another priority queue of same type and size.
            * emplace() - insert a new element into the priority queue container, the new element is added to the top of the priority queue.

        ? Deque
            Double ended queues are sequence containers with the feature of expansion and contraction on both the ends.
            They are similar to vectors, but are more efficient in case of insertion and deletion of elements.
            Unlike vectors, contiguous storage allocation may not be guaranteed.
            * insert()
            * rbegin()
            * rend()
            * assign()
            * resize()
            * push_front()
            * push_back()
            * pop_front()
            * pop_back()
            * front()
            * back()
*/


Measured memory_bytes: 3624