#include using namespace std; #define int long long #define rep(i, n) for(int i = 0; i < (int)(n); ++i) int solve(void) { string N; cin >> N; const int L = N.size(); string S1(L, '4'); if(N < S1) { string ans(L - 1, '5'); cout << ans << "\n"; return 0; } string S2(L, '5'); if(S2 <= N) { cout << S2 << "\n"; return 0; } rep(i, L) { if(N[i] == '4' or N[i] == '5') continue; string ans = N; for(int j = i; j < L; ++j) ans[j] = '5'; if(N[i] < '4') { for(int j = i - 1; j >= 0; --j) { if(ans[j] == '4') ans[j] = '5'; else if(ans[j] == '5') {ans[j] = '4'; break;} } } cout << ans << "\n"; return 0; } cout << N << "\n"; return 0; } signed main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int Testcases = 1; //cin >> Testcases; while(Testcases--) solve(); return 0; }