#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using ull = unsigned long long; using Graph = vector>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define NP next_permutation const int INF32 = 2e9; const ll INF64 = 2e18; const ll mod = 998244353; // const ll mod = 1e9 + 7; template bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} void cincout() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } int main() { cincout(); string S; cin >> S; int id = -1; for (int i = 0; i < S.size(); i++) { if (S[i] == '3') { id = i; break; } } S[id] = '2'; for (int i = id + 1; i < S.size(); i++) S[i] = '9'; int sum = 0; for (char c : S) sum += (c - '0'); if (sum % 3 != 0) { cout << S << endl; return 0; } for (int i = S.size() - 1; i >= 0; i--) { int x = S[i] - '0'; if (sum % 3 == 0) x -= 1; if (x == 3) x--; if (x < 0) continue; else { S[i] = x + '0'; break; } } cout << S << endl; }