#include<iostream> #include<queue> using namespace std; typedef long long ll; int n; void bfs(ll x){ queue<ll> q; q.push(x); while( !q.empty() ){ ll t = q.front(); q.pop(); if(t % n == 0){ cout << t << endl; return; } q.push(t*10); q.push(t*10 + 1); } } int main(){ ios::sync_with_stdio(false); while(cin >> n){ if(n == 0) break; bfs(1); } return 0; }