#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int flag[100];
char st[100];
int n,a[100000],b[100000],c[100000];
void init()
{
    for (int i=0;i<=9;++i) flag[i]=0;
    return;
}
int main()
{
    //freopen("e.in","r",stdin);
    //freopen("e.out","w",stdout);
    scanf("%s",st);
    n=strlen(st);
    for (int i=1;i<=n;++i) a[i]=(int)(st[i-1])-48;
    if (a[1]<5) a[1]+=5;else a[1]-=5;
    for (int i=1;i<=n;++i) ++flag[a[i]];
    bool FLAG=1;
    for (int i=0;i<=9;++i) if (flag[i]>1) {FLAG=0;break;}
    if (FLAG) {for (int i=1;i<=n;++i) printf("%d",a[i]);cout<<endl;return 0;}
    for (int i=1;i<=n;++i) b[i]=c[i]=a[i];
    bool flag1=0,flag2=0;
    while (1)
    {
        bool ttt=0;
        if (b[0]==0 && flag1==0)
        {
            bool Flag=1;
            init();
            for (int i=1;i<=n;++i)
            {
                if (flag[b[i]]) {Flag=0;++b[i];int t=i;while (b[t]>9) b[t]=0,++b[t-1],--t;for (int j=i+1;j<=n;++j) b[j]=0;break;}
                flag[b[i]]=1;
            }
            if (Flag) flag1=1;
            ttt=1;
        }
        if (c[0]==0 && flag2==0)
        {
            bool Flag=1;
            init();
            for (int i=1;i<=n;++i)
            {
                if (flag[c[i]]) {Flag=0;--c[i];int t=i;while (c[t]<0) c[t]=9,--c[t-1],--t;for (int j=i+1;j<=n;++j) c[j]=9;break;}
                flag[c[i]]=1;
            }
            if (Flag) flag2=1;
            ttt=1;
        }
        if (!ttt) break;
    }
    long long A=0LL,B=0LL,C=0LL;
    for (int i=1;i<=n;++i) B=B*10+b[i];
    for (int i=1;i<=n;++i) C=C*10+c[i];
    for (int i=1;i<=n;++i) A=A*10+a[i];
    //cout<<A<<endl<<B<<endl<<C<<endl<<endl;
    if (B-A>=A-C || b[0]!=0) {for (int i=1;i<=n;++i) printf("%d",c[i]);cout<<endl;}else {for (int i=1;i<=n;++i) printf("%d",b[i]);cout<<endl;}
    return 0;
}