#include
#include
#include <string.h>
#include
#include
using namespace std;
int n;
long long t;
void bfs()
{
queue<long long >q;
q.push(1);
while(!q.empty())
{
t=q.front();
q.pop();
if(t%n==0)
{
printf("%lld\n",t);
break;
}
q.push(t*10);
q.push(t*10+1);
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n!=0)
{
bfs();
}
return 0;
}