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.
#Beautiful Year 

import math
#Definicion de funciones
def dig_distintos(lista): 
    v = 0
    for i in lista:
        if lista.count(i)>1:
            v = v+1  
    if v==0:
        return True
    else:
        return False
def tens(lista):
    if lista.count(10)!=0:
        return True
    else:
        return False
def dig_repetidos(lista):
    while dig_distintos(lista)==False or tens(lista)==True:
        
        #What happen if there is a 10?
        while tens(lista)==True:
            ten_position = lista.index(10)
            lista[lista.index(10)-1] = lista[lista.index(10)-1] + 1
            lista[ten_position] = 0
            
        #At this poit we know there is no tens in the list
        if dig_distintos(lista)==False and tens(lista)==False:
            for i in lista:
                c = 1
                if lista.count(i)>1:
                    for j in range(lista.index(i)+1, 4, 1):
                        if i==lista[j]:
                            lista[j] = lista[j] + c
                            c = c + 1
            
    return lista

y = int(input())

a = y
year = []
while a>0:
    r = a%10
    a = a//10
    year.insert(0,r)

if dig_distintos(year)==True:
    year[3] = year[3] + 1
    if year[3]>9:
        year[2] = year[2] + 1
        year[3] = 0
        if year[2]>9:
            year[1] = year[1] + 1
            year[2] = 0
            if year[1]>9:
                year[0] = year[0] + 1
                year[1] = 0
#print(year)

# Cambio de dígitos si están repetidos 


dig_repetidos(year)
    

#Conversion al sistema decimal 
d = 3 #potencia inicial
z = 0 #acomulador
for k in year:
    e = k*(10**d)
    d = d-1
    z = z + e

print(z)
    











