A repetition-free number is one in which each digit $\{1,2,3,…,9\}$ appears at most once and the digit $0$ does not appear. A repetition-free number can have at most nine digits, but may also have fewer than nine digits. Some examples of repetition-free numbers are $9, 32, 489, 98761$ and $983245$.
You will be given an integer $N$ with at most nine digits. Your task is to print out the smallest repetition-free number bigger than $N$. For example, for $99$ the answer is $123$, for $881$ the answer is $891$, and for $133$ the answer is $134$.

-----Input:-----
A single line with a single integer with at most $9$ digits.

-----Output:-----
A single line containing the smallest repetition-free number bigger than the given number. If there is no repetition-free number bigger than the given number, print $0$.

-----Constraints:-----
- $N$ consists of atmost $9$ digits

-----Sample input-----
99

-----Sample output-----
123

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
N = int(input())
i = N + 1
flag = 0
for i in range(N + 1, 987654321):
	a = str(i)
	b = list(a)
	c = set(a)
	if '0' not in b:
		if len(b) == len(c):
			print(i)
			flag += 1
			break
if flag < 1:
	print(0)


n = int(input())
if n > 999999999 or n < -999999999:
	print(0)
else:
	n += 1
	f = False
	p = False
	while n <= 987654321:
		k = str(n)
		if k.count('0') == 0:
			for i in range(len(k)):
				if k.count(k[i]) > 1:
					p = True
					break
			if p:
				p = False
			else:
				f = True
				break
		n += 1
	if f:
		print(n)
	else:
		print(0)


check = int(input()) + 1
while check <= 987654321:
	val = str(check)
	temp = set(val)
	if len(temp) == len(val) and '0' not in temp:
		break
	else:
		check += 1
if check <= 987654321:
	print(check)
else:
	print(0)


try:
	n = int(input())
	n += 1
	flag = 1
	while n <= 987654321:
		nt = str(n)
		if '0' not in nt:
			if len(nt) == len(set(list(nt))):
				print(n)
				flag = 0
				break
			n += 1
		else:
			nt = nt[::-1]
			ind = nt.index('0')
			n += 10 ** ind
	if flag:
		print(0)
except:
	pass


n = int(input()) + 1
flag = 0
while n <= 987654321:
	digits = [str(x) for x in str(n)]
	if '0' in digits:
		n += 1
		continue
	else:
		n += 1
		j = len(digits)
		s = len(list(set(digits)))
		if j == s:
			print(''.join(digits))
			flag = 1
			break
if flag == 0:
	print('0')