#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>
#include <array>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

class InputType2
{
public:
    InputType2(size_t n)
        : n_(n)
    {}
    template<class T>
    operator T() const {
        Input<T> i{};
        return i(n_);
    }
private:
    size_t n_;
};

auto input() {
    return InputType();
}

template<class... Args>
auto input(Args&&... args) {
    return InputType2(std::forward<Args>(args)...);
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

using ll = long long;
using ull = unsigned long long;

auto gcd(size_t l, size_t r) {
    if (r == 0)
        return l;
    return gcd(r, l % r);
}

auto gcd(size_t a, size_t b, size_t c) {
    return gcd(a, gcd(b, c));
}

constexpr const double pi = 3.14159265358979323846264338327950288;

template<class T, T N>
class basic_mod {
public:
    basic_mod()
        : v_{}
    {}
    template<class U>
    basic_mod(U&& v)
        : v_(std::forward<U>(v))
    {}
    template<class U>
    basic_mod& operator=(U&& v) {
        v_ = std::forward<U>(v);
        return *this;
    }
    basic_mod& operator+=(const basic_mod& v) {
        v_ = (v_ % N + v.v_ % N) % N;
        return *this;
    }
    basic_mod& operator-=(const basic_mod& v) {
        v_ = (v_ % N - v.v_ % N) % N;
        return *this;
    }
    basic_mod& operator*=(const basic_mod& v) {
        v_ = (v_ % N * v.v_ % N) % N;
        return *this;
    }
    basic_mod operator+(const basic_mod& v) {
        basic_mod m(v_);
        m += v;
        return m;
    }
    basic_mod operator-(const basic_mod& v) {
        basic_mod m(v_);
        m -= v;
        return m;
    }
    basic_mod operator*(const basic_mod& v) {
        basic_mod m(v_);
        m *= v;
        return m;
    }
    const T& value() const noexcept {
        return v_;
    }
private:
    T v_{};
};

template<auto N>
using mod = basic_mod<decltype(N), N>;

template<class T, T N = T(1000000007), std::size_t M = 510000>
class com {
public:
    com() noexcept {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < M; i++) {
            fac[i] = fac[i - 1] * i % N;
            inv[i] = N - inv[N % i] * (N / i) % N;
            finv[i] = finv[i - 1] * inv[i] % N;
        }
    }
    constexpr T operator()(T n, T i) const noexcept {
        if (n < i || n < 0 || i < 0)
            return 0;
        return fac[n] * (finv[i] * finv[n - i] % N) % N;
    };
private:
    T fac[M];
    T finv[M];
    T inv[M];
};

size_t f(size_t x) {
    size_t c = 0;
    for (size_t i = 1; i * i <= x; ++i) {
        if (x % i == 0) {
            if (i * i == x)
                ++c;
            else
                c += 2;
        }
    }
    return c;
}

int main() {
    size_t n = input();
    auto a = n / 1000 + 1 * (n % 1000 == 0 ? 0 : 1);
    cout << 1000 * a - n << endl;
    return 0;
}


Measured memory_bytes: 3620