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.

Input

The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.

Output

Print a single integer — the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.

Examples

Input

1987


Output

2013


Input

2013


Output

2014
from sys import stdin, exit as sys_exit
n = input()
A = [int(n[0]),int(n[1]),int(n[2]),int(n[3])]
if A[1] == A[0]:
    A[2] = 0
    A[3] = 0
    A[1] += 1
    i = 1
    while i in A:
        i += 1
    A[3] = i
    print(*A,sep = '')
elif A[2] == A[1] or A[2] == A[0]:
    A[3] = -1
    i = A[2] + 1
    while i in A and i < 10:
        i += 1
    if i == 10:
        A[2] = 0
        A[1] += 1
        if A[1] == 10:
            A[1] = 0
            A[0] += 1
            i = 1
            while i in A:
                i += 1
            A[2] = i
            while i in A:
                i += 1
            A[3] = i
            print(*A,sep = '')
        else:
            i = 1
            while i in A:
                i += 1
            A[3] = i
            print(*A,sep = '')
    else:
        A[2] = i
        i = 0
        while i in A:
            i += 1
        A[3] = i
        print(*A,sep = '' )
else:
    i = A[3]
    while i in A and i < 10:
        i += 1
    if i == 10:
        A[3] = 0
        A[2] += 1
        if A[2] == 10:
            A[2] = 0
            A[1] += 1
            if A[1] == 10:
                A[1] = 0
                A[0] += 1
                
                A[3] = -1
                i = A[2] + 1
                while i in A and i < 10:
                    i += 1
                if i == 10:
                    A[2] = 0
                    A[1] += 1
                    if A[1] == 10:
                        A[1] = 0
                        A[0] += 1
                        i = 1
                        while i in A:
                            i += 1
                        A[2] = i
                        while i in A:
                            i += 1
                        A[3] = i
                        print(*A,sep = '')
                    else:
                        i = 1
                        while i in A:
                            i += 1
                        A[3] = i
                        print(*A,sep = '')
                else:
                    A[2] = i
                    i = 0
                    while i in A:
                        i += 1
                    A[3] = i
                    print(*A,sep = '' )                
            elif A[1] == A[0]:
                A[2] = 0
                A[3] = 0
                A[1] += 1
                i = 1
                while i in A:
                    i += 1
                A[3] = i
                print(*A,sep = '')
            else:
                i = 1
                while i in A:
                    i += 1
                A[3] = i
                print(*A,sep = '')
        elif A[2] == A[1] or A[2] == A[0]:
            A[3] = -1
            i = A[2] + 1
            while i in A and i < 10:
                i += 1
            if i == 10:
                A[2] = 0
                A[1] += 1
                if A[1] == 10:
                    A[1] = 0
                    A[0] += 1
                    i = 1
                    while i in A:
                        i += 1
                    A[2] = i
                    while i in A:
                        i += 1
                    A[3] = i
                    print(*A,sep = '')
                else:
                    i = 1
                    while i in A:
                        i += 1
                    A[3] = i
                    print(*A,sep = '')
            else:
                A[2] = i
                i = 0
                while i in A:
                    i += 1
                A[3] = i
                print(*A,sep = '' ) 
        else:
            i = 0
            while i in A:
                i += 1
            A[3] = i
            print(*A,sep = '')
    else:
        A[3] = i
        print(*A,sep = '')