#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using vec_i = std::vector<int>;
using vec_ll = std::vector<ll>;
using vec_ld = std::vector<ld>;
using set_i = std::set<int>;
using set_ll = std::set<ll>;
using set_ld = std::set<ld>;
using uset_i = std::unordered_set<int>;
using uset_ll = std::unordered_set<ll>;
using uset_ld = std::unordered_set<ld>;
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  std::cin >> N;
  int n = N % 1000;
  if (n == 0) {
    std::cout << 0 << "\n";
    return 0;
  }
  std::cout << 1000 - n << "\n";
  return 0;
}
