#include <bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

    // /* ----------------------------------------

// Data types
#define ll long long
#define db double
#define ull unsigned long long

// Pairs
#define pii pair<int, int>
#define pLL pair<ll, ll>
#define pdd pair<db, db>
#define fi first
#define se second
#define mp make_pair

// Containers
#define pb push_back
#define popb pop_back
#define eb emplace_back
#define pf push_front // ø.deque
#define popf pop_front // ø.deque
#define ef emplace_front // ø.deque
#define vi vector<int> 
#define vs vector<string>
#define vL vector<ll>
#define vc vector<char>
#define vb vector<bool>

// For loop
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repb(i, n) for (ll i = 1; i <= n; i++)
#define rrep(i, n) for (ll i = n; i >= 0; i--)
#define rrepb(i, n) for (ll i = n; i > 0; i--)

// Searching and Sorting
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define vsort(v) sort(all(v))
#define vsortr(v) sort(rall(v))
#define bs(x, y) binary_search(x.begin(), x.end(), y)
#define cpresent(c, x) ((c).find(x) != (c).end()) 
#define vpresent(c, x) (find(all(c),x) != (c).end()) 

// Math
#define sqr(x) ((x) * (x))
#define cbe(x) ((x) * (x) * (x))
#define lcm(x, y) (x / __gcd(x, y)) * y

// Debug
#define watch(x) cout << (#x) << " is " << (x) << endl

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// -------------------------------------------- */

const double pi = acos(-1.0); 
void solve();

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}

void read_and_write() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout); 
    #endif
}

int main() {
    read_and_write();
    fastio(); 

    solve(); /* --- test case input ---

    int t; 
    cin >> t;
	// int totalTestCases = t;

    while (t--) { 
    	// cout << "Case #" << totalTestCases - t << ": ";
    	solve();
	}
// ------------ */ 

    return 0;
}

void solve() {
	ll n;
    cin >> n;
   	ll tmp = ceil(n / (double) 1000) * 1000;
   	cout << tmp - n << "\n";
} 

Measured memory_bytes: 3612