#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
ll computeKeta(int K) {
    return 81 * (ll) round(pow(2, K - 1) - 1);
}

ll computeKaku1(int rest) {
    return 9 * (ll) round(pow(2, rest) - 1);
}

ll computeKaku2(int rest) {
    return (ll) round(pow(2, rest));
}

bool solve() {
    ll N;
    cin >> N;

    if (N == 0) return false;

    int K = 1;
    while (N > computeKeta(K)) {
        N -= computeKeta(K);
        K++;
    }

    vector<int> ans(K);
    int state = 0;//何種類決まったか
    int num1, num2;//使用する数字

    for (int i = 1; i <= 9; i++) {
        if (N <= computeKaku1(K - 1)) {
            ans[0] = i;
            num1 = i;
            state = 1;
            break;
        } else {
            N -= computeKaku1(K - 1);
        }
    }

    //2 ~ K - 1桁目を決めていく
    for (int i = 1; i < K - 1; i++) {
        if (state == 1) {
            int rest = K - i - 1;
            for (int j = 0; j <= 9; j++) {
                if (j == num1) {
                    if (N > computeKaku1(rest)) {
                        N -= computeKaku1(rest);
                    } else {
                        ans[i] = j;
                        break;
                    }
                } else {
                    if (N > computeKaku2(rest)) {
                        N -= computeKaku2(rest);
                    } else {
                        ans[i] = j;
                        num2 = j;
                        state = 2;
                        if (num1 > num2) swap(num1, num2);
                        break;
                    }
                }
            }
        } else {
            int rest = K - i - 1;
            if (N > computeKaku2(rest)) {
                N -= computeKaku2(rest);
                ans[i] = num2;
            } else {
                ans[i] = num1;
            }
        }
    }

    //最後の桁を決める
    if (state == 1) {
        ans[K - 1] = N - 1;
        if(ans[K - 1] >= num1){
            ans[K-1]++;
        }
    } else {
        if (N == 2) {
            ans[K - 1] = num2;
        } else {
            ans[K - 1] = num1;
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i];
    }
    cout << endl;
    return true;


}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (solve()) {

    }


    return 0;
}



Measured memory_bytes: 3360