#include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; template using VV = vector>; #define REP(i, n) for(i64 i = 0; i < i64(n); i++) #define REP1(i, n) for(i64 i = 1; i <= i64(n); i++) i64 INF = 100100100100100L; i64 direct[8][2] = { {1, 0}, {0, -1}, {-1, 0}, {0, 1}, {1, -1}, {-1, -1}, {-1, 1}, {1, 1} }; template ostream &operator<<(ostream &os, pair p); template ostream &operator<<(ostream &os, const vector &v) { for(i64 i = 0; i < i64(v.size()); i++) { if (i > 0) os << ' '; os << v[i]; } return os; } template ostream &operator<<(ostream &os, const set &st) { bool first = true; for(const T &it: st) if (first) { first = false; os << it; } else{ os << ' ' << it; } return os; } template ostream &operator<<(ostream &os, map &mp) { bool first = true; for(const auto &[f, l]: mp) if (first) { first = false; os << '{' << f << "-> " << l << '}'; } else{ os << ", {" << f << "-> " << l << '}'; } return os; } template ostream &operator<<(ostream &os, pair p) { os << '{' << p.first << ", " << p.second << '}'; return os; } int main() { string N; cin >> N; vector a; for(char ch: N) a.push_back(ch - '0'); bool baka = false; for(i64 i = 0; i < i64(a.size()); i++) { if (baka) { a[i] = 9; continue; } if (a[i] == 3) { a[i] = 2; baka = true; continue; } } i64 sum = 0; for(i64 it: a) sum += it; if (sum % 3 == 0) { i64 p = a.size() - 1; while (true) { if (a[p] == 0) { a[p] = 9; p--; continue; } a[p]--; if (a[p] == 3) a[p]--; break; } } for(i64 it: a) cout << it; cout << endl; return 0; }