#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; while(true){ bool ok = false; for(auto &c : s){ if(ok) c = '9'; else if(c == '3') ok = true,c--; } int sum = 0; for(auto c : s) sum += c-'0'; if(sum%3) break; for(int i=s.size(); i--;){ if(s.at(i) == '0') s.at(i) = '9'; else{s.at(i)--; break;} } } while(s.size() && s.at(0) == '0') s.erase(s.begin()); cout << s << endl; }