#include using namespace std; bool is_nabeatsu(string N){ int digitsum = 0; for (char c:N) digitsum += c - '0'; return digitsum % 3 ==0 || find(N.begin(), N.end(), '3') != N.end(); } int main(){ string N; cin >> N; assert(N.size() <= 1000000 || N == "1" + string(1000000, '0')); assert(N[0] != '0'); while (is_nabeatsu(N)){ auto it = find(N.begin(), N.end(), '3'); if (it == N.end()){ for (int i = N.size() - 1;; i--){ if (N[i] == '0') N[i] = '9'; else{ N[i]--; break; } } } else{ *it = '2'; while(++it != N.end()) *it = '9'; } } cout << N << endl; return 0; }