#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } string dec(string s) { if (s == "4") return ""; int n = s.size(); for (int i = n - 1; i >= 0; i--) { if (s[i] == '4') continue; return s.substr(0, i) + "4" + string(n - 1 - i, '5'); } return string(n - 1, '5'); } void solve() { string s; cin >> s; int n = s.size(); string ans = s; rep(i, 0, n) { if (s[i] == '4' || s[i] == '5') continue; if (s[i] <= '3') { if (i == 0) ans = string(n - 1 - i, '5'); else ans = dec(s.substr(0, i)) + string(n - i, '5'); } else { ans = s.substr(0, i) + string(n - i, '5'); } break; } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }