#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,h;
cin>>n;
m=n%1000;
h=n/1000;
if(h>m){
cout<<n;
}else{
cout<<m*1000+h;
}
}
/**************************************************************
Problem: 1631
User: wengsihan
Language: C++
Result: Accepted
Time:7 ms
Memory:2072 kb
****************************************************************/