int _tmain()
{
// TODO: Please replace the sample code below with your own.
int n=10000;
int f[100];
while (cin>>n,n)
{
int f4=1;
int f10=1;
int i=0;
f[0]=0;
int sum=0;
while (f[i]<n)
{
i++;
f10*=10;
f[i] = f10-1-f4;
f4 = f4*9+f10;
}
i--;
f[0] = 0;
int r=n;
while (i>=0)
{
int num = r/(f[i]+1);
r -= num*(f[i]+1);
i--;
if (num>=4) num++;
cout<<num;
}
cout<<endl;