#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin>>n; int f=(n/100%10)*100+(n/10%10)*10+n%10; if(f==0)cout<<0; else { if(f<=500)cout<<f; else cout<<1000-f; } return 0; }