#include<stdio.h>
int main () {
	int konec = 0, cislo, pomoc, i, sucet, sucet2, k, a, konec3, konec2;
	int cifry[10];
	while (konec == 0) {
		scanf("%d", &cislo);
		if (cislo == 0)
			konec = 1;
		if (konec == 0) {
			k = 0;
			a = 10;
			pomoc = cislo;
			konec3 = 0;
			while (konec3 == 0) {
				cifry[k] = (pomoc % a) / (a/10);
				pomoc = pomoc - cifry[k] * (a/10);
				a = a *10;
				k++;
				if (pomoc == 0)
					konec3 = 1;
			}
			sucet2 = 0;
			for (a = 0; a < k; a++) {
				sucet2 = sucet2 + cifry[a];
			}
		}
		if (konec == 0) {
			konec2 = 0;
			i = 11;
			while (konec2 == 0) {
				pomoc = cislo;
				pomoc = pomoc * i;
				k = 0;
				a = 10;
				konec3 = 0;
				while (konec3 == 0) {
					cifry[k] = (pomoc % a) / (a/10);
					pomoc = pomoc - (cifry[k] * (a/10));
					a = a * 10;
					
					k++;
					if (pomoc == 0) {
						konec3 = 1;
					 }
				}
				sucet = 0;
				for (a = 0; a < k; a++) {
					sucet = sucet + cifry[a];
				}
				i++;
				if (sucet == sucet2) {
					printf("%d\n", (i-1));
					konec2 = 1;
				}
				
			}
		}	
	}
	return 0;
}
