import java.io.IOException; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam32 */ public class easy { public static void main(String[] args) throws IOException { String cislo; while (!(cislo = nextLine()).equalsIgnoreCase("0")) { int soucet = sectiSlozky(cislo+""); int c2 = Integer.parseInt(cislo); int c = 11; while(true) { if (sectiSlozky((c2*c)+"")==soucet) { System.out.println(c); break; }else{ c++; } } } } public static int sectiSlozky(String str) { int soucet = 0; for (int i = 0; i < str.length(); i++) { soucet += Byte.parseByte(str.charAt(i)+"") ;//Math.pow(Byte.parseByte(str.charAt(i) + ""), i + 1); } return soucet; } public static String nextLine() throws IOException { int z; String ret = ""; while ((z = ((char) (System.in.read()))) != '\n') { ret += (char) z; } return ret; } }