n=input();r=0while n: r+=1;k=t=1 for _ in`r`:t&=(r/k/10*k+r%k)%(r/k%10or r)<1;k*=10 n-=tprint r
165
9999
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!