It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.

Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
The single line contains integer *y* (1000 ≤ *y* ≤ 9000) — the year number.
a=input()
d=""
q=0
for i in range(4):
    if a[i]=="0":
        q+=1
if q<=1:
    
    if a[1]=="9":
        k=int(a[0])+1
        d+=str(k)
        d+="01"
        if k==3:
            d+="4"
        else:
            d+="3"
    else:
        d+=a[0]
        if a[2]=="9":
            m=int(a[1])+1
            d+=str(m)
            d+="0"
            for i in range(1,10):
                if i!=m and i!=int(a[0]):
                    d+=str(i)
                    break
        else:
            d+=a[1]
            if a[3]=="9":
                n=int(a[2])+1
                d+=str(n)
                d+="0"
            else:
                d+=a[2]
                for i in range(1,10):
                    if i!=int(a[1]) and i!=int(a[0]) and i!=int(a[2]):
                        d+=str(i)
                        if int(d)>int(a):
                            break
                        else:
                            j=d
                            for w in range(1,10):
                                if w!=int(a[1]) and w!=int(a[0]) and w!=int(a[2]) and w!=int(a[3]):
                                    r=w-int(a[3])
                                    break
                            d=str(int(j)+r)
                            break
elif q==2 and a[1]==a[2]=="0":
    d+=a[0]
    d+=a[1]
    if a[3]!="9":
        if a[0]==1:
            d+="23"
        else:
            d+="1"
            for w in range(2,10):
                if w!=int(a[0]) :
                    d+=str(w)
                    break
    else:
        if a[0]==1:
            d+="23"
        else:
            d+="1"
            for w in range(2,10):
                if w!=int(a[0]):
                    d+=str(w)
                    break
elif q==2 and a[1]==a[3]=="0":
    d+=a[0]
    if a[2]=="9":
        if a[0]=="1":
            d+="203"
        else:
            d+="10"
            for w in range(2,10):
                if w!=int(a[0]):
                    d+=str(w)
                    break
    else:
        d+="0"
        if a[0]==a[2]:
            j=int(a[2])+1
            d+=str(j)
            for w in range(1,10):
                if w!=int(a[0]) and w!=j:
                    d+=str(w)
                    break
        else:
            d+=a[2]
            for w in range(1,10):
                if w!=int(a[0]) and w!=int(a[2]):
                    d+=str(w)
                    break
elif q==2 and a[2]==a[3]=="0":
    d+=a[0]
    d+=a[1]
    d+="0"
    for w in range(1,10):
        if w!=int(a[0]) and w!=int(a[1]):
            d+=str(w)
            break
elif q==3:
    d+=a[0]
    d+=a[1]
    for w in range(1,10):
        if w!=int(a[0]):
            u=w
            d+=str(w)
            break
    for g in range(1,10):
        if g!=int(a[0]) and g!=u:
            d+=str(g)
            break
print(str(d))                
                