#include <bits/stdc++.h>
using namespace std;
long long M, N;
void solve() {
  cin >> N;
  long long K = N / 1000;
  if (N % 1000 != 0) {
    K = floor(K) + 1;
    cout << K * 1000 - N << '\n';
  } else
    cout << 0 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
