public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		while (true)
		{
			int n = in.nextInt();
			if (n == 0)
				break;
			BigInteger N = new BigInteger(""+n);
			BigInteger current = new BigInteger(""+n);
			if (n == 90)
				current = new BigInteger("1111111110");
			if (n == 180)
				current = new BigInteger("11111111100");
			
			while (true)
			{
				int firstInvalid = firstInvalid(current.toString());
				int firstZero = firstZero(current.toString());
				if (firstInvalid == -1)
				{
					System.out.println(current.toString());
					break;
				}
				
				if (firstZero == -1)
					current = BigInteger.TEN.pow(current.toString().length());
				else
					current = new BigInteger(current.toString().substring(0,current.toString().length()-firstZero-1)+BigInteger.TEN.pow(firstZero).toString());
				if (current.mod(N).equals(BigInteger.ZERO) == false)
				{
					BigInteger divisor = current.divide(N);
					current = N.multiply(divisor).add(N);
				}
			}
			
		}
	}