#include <iostream>

using namespace std;

inline
int sumDigits(int n) {
    int r = 0;
    while(n) {
        r += n %10;
        n/=10;
    }
    return r;
}

int main() {
    int n;
    char buf[100100];

    while(1) {
        n = 0;
        buf[0] = cin.get();
        if( !isdigit(buf[0]) && buf[0] != '-') return 0;
        do {
            n++;
            buf[n] = cin.get();
        } while( buf[n] != '\n' );
        buf[n] = 0;
        if( buf[0] != '-' ) {
            int lastlowerable = n-1, firstraisable = -1;
            bool found = false;
            for( int i = n-2; i >= 0 && !found; i-- ) {
                if( buf[i] >= '1' ) {
                    for( int j = i+1; j < n; j++ ) {
                        if( buf[j] <= '7' ) {
                            firstraisable = j;
                            break;
                        }
                    }
                    if( firstraisable != -1 ) {
                        found = true;
                        buf[firstraisable]+=2;
                        buf[i]-=1;
                        if( buf[0] >= '1' )
                            cout << buf << endl;
                        else {
                            for( int k = n-1; k > 2 && buf[1] < '9'; k-- ) {
                                while( (buf[1] < '9') && (buf[k] >= '1') ) {
                                    buf[1] += 1;
                                    buf[k] -= 1;
                                }
                            }
                            cout << (buf+1) << endl;
                        }
                        break;
                    }
                    int j;
                    for( j = i+1; j < n; j++ ) {
                        if( buf[j] <= '8' ) {
                            firstraisable = j;
                            break;
                        }
                    }
                    for( j++ ; j < n && firstraisable != -1; j++ ) {
                        if( buf[j] <= '8' && firstraisable != -1 ) {
                            found = true;
                            buf[firstraisable]++;
                            buf[j]++;
                            buf[i]--;
                            if( buf[0] >= '1' )
                                cout << buf << endl;
                            else {
                                for( int k = n-1; k > 2 && buf[1] < '9'; k-- ) {
                                    while( (buf[1] < '9') && (buf[k] >= '1') ) {
                                        buf[1] += 1;
                                        buf[k] -= 1;
                                    }
                                }
                                cout << (buf+1) << endl;
                            }
                            break;
                        }
                    }
                    firstraisable = -1;
                }

            }
            if(found) continue;
            for( int i = n-1; i >= 0; i-- ) {
                if (buf[i] <= '8') {
                    buf[i] += 1;
                    cout << "-" << buf << endl;
                    found = true;
                    break;
                }
            }
            if(!found)
                cout << "-1" << (buf) << endl;
        } else {
            bool found = false;
            for( int i = n-1; i > 0; i-- ) {
                if(buf[i] <'9') {
                    buf[i] += 1;
                    cout << buf << endl;
                    found = true;
                    break;
                }
            }
            if( !found ) {
                cout << "-1" << (buf+1) << endl;
            }
        }
    }
}