from itertools import permutations as p for i in range(1,10**4): k=[int("".join(j))for j in p(str(i))if int(j[0])and j==j[::-1]] if k:print(min(k))