#include <bits/stdc++.h>
using namespace std;
long long t, n, m, k, a[300010], q, l, r;
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n;
  cout << ((1000 - n % 1000)) % 1000;
  return 0;
}
