w;main(z){for(;~scanf(z="%d\n",&w);)printf(z,r(w,1,0));}r(v,i,s){for(;i++(w=r(v/i,1,0))?s:w;for(;v;v/=10)s+=v%10;return s;}