#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

ll llpow(ll a, ll x){
    ll res = 1;
    REP(i,x){
        res *= a;
    }
    return res;
}

ll f(ll x){
    if(x<=1)return 1;
    else return 9*(llpow(2,x-1)-1);
}

ll g(ll x){
    if(x<=1)return 1;
    else return (llpow(2,x-1));
}

int main() {
    while(1){
        ll n;
        cin >> n;
        if(n == 0)break;
        ll sum = 0, k = 2;
        while(1){
            ll tmp;
            tmp = 45*(llpow(2,k)-2) - f(k);
            if(sum+tmp >= n)break;
            sum += tmp;
            k++;
        }
        vector<int> ans,use;
        REP(i,k){
            REP(j,10){
                if(i==0&&j==0)continue;
                if(i==k-1 && use.size()==1 && ans[0]==j)continue;
                ll tmp;
                if(i==0||j==ans[0]){
                    tmp = f(k-i);
                }
                else{
                    tmp = g(k-i);
                }
                if(sum+tmp>=n){
                    ans.push_back(j);
                    if(use.size()==0 || ans[0]!= j){
                        use.push_back(j);
                    }
                    break;
                }
                sum += tmp;
            }
            if(use.size()>1)break;
        }
        sort(use.begin(),use.end());
        while(ans.size()<k){
            REP(j,2){
                ll tmp;
                tmp = g(k-ans.size());
                if(sum+tmp>=n){
                    ans.push_back(use[j]);
                    break;
                }
                sum += tmp;
            }
        }

        REP(i,k){
            cout << ans[i];
        }
        cout << endl;
    }

    return 0;
}

