#include <bits/stdc++.h>
using namespace std;
int N;
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f |= (ch == '-');
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f ? -x : x;
}
signed main() {
  N = read();
  printf("%d", (1000 - (N % 1000)) % 1000);
  return 0;
}
