#include<cstdio> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<vector> #include<queue> #include<stack> using namespace std; void bfs(int n) { queue<long long>q; while(!q.empty()) { q.pop(); } q.push(1); while(!q.empty()) { long long current =q.front(); q.pop(); if(current%n==0) { cout<<current<<endl; return; } q.push(current*10); q.push(current*10+1); } } int main() { int n; while(cin>>n) { if(n==0) break; bfs(n); } return 0; }