#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

bool judge(ll n) { return false; }

int main() {
  ll K;
  scanf("%lld", &K);

  ll ans = 0;
  ll count = 0;
  bool done = false;
  ll keta = 1;
  for (ll i10 = 0; !done && i10 <= 9; i10++) {
    if (i10 > 0 && keta < 10) keta = 10;

    ll s9 = (keta < 10) ? 0 : max(i10 - 1, 0LL);
    ll e9 = (keta < 10) ? 9 : min(i10 + 1, 9LL);

    for (ll i9 = s9; !done && i9 <= e9; i9++) {
      if (i9 > 0 && keta < 9) keta = 9;

      ll s8 = (keta < 9) ? 0 : max(i9 - 1, 0LL);
      ll e8 = (keta < 9) ? 9 : min(i9 + 1, 9LL);

      for (ll i8 = s8; !done && i8 <= e8; i8++) {
        if (i8 > 0 && keta < 8) keta = 8;

        ll s7 = (keta < 8) ? 0 : max(i8 - 1, 0LL);
        ll e7 = (keta < 8) ? 9 : min(i8 + 1, 9LL);

        for (ll i7 = s7; !done && i7 <= e7; i7++) {
          if (i7 > 0 && keta < 7) keta = 7;

          ll s6 = (keta < 7) ? 0 : max(i7 - 1, 0LL);
          ll e6 = (keta < 7) ? 9 : min(i7 + 1, 9LL);
          for (ll i6 = s6; !done && i6 <= e6; i6++) {
            if (i6 > 0 && keta < 6) keta = 6;

            ll s5 = (keta < 6) ? 0 : max(i6 - 1, 0LL);
            ll e5 = (keta < 6) ? 9 : min(i6 + 1, 9LL);
            for (ll i5 = s5; !done && i5 <= e5; i5++) {
              if (i5 > 0 && keta < 5) keta = 5;

              ll s4 = (keta < 5) ? 0 : max(i5 - 1, 0LL);
              ll e4 = (keta < 5) ? 9 : min(i5 + 1, 9LL);
              for (ll i4 = s4; !done && i4 <= e4; i4++) {
                if (i4 > 0 && keta < 4) keta = 4;

                ll s3 = (keta < 4) ? 0 : max(i4 - 1, 0LL);
                ll e3 = (keta < 4) ? 9 : min(i4 + 1, 9LL);

                for (ll i3 = s3; !done && i3 <= e3; i3++) {
                  if (i3 > 0 && keta < 3) keta = 3;

                  ll s2 = (keta < 3) ? 0 : max(i3 - 1, 0LL);
                  ll e2 = (keta < 3) ? 9 : min(i3 + 1, 9LL);
                  for (ll i2 = s2; !done && i2 <= e2; i2++) {
                    if (i2 > 0 && keta < 2) keta = 2;

                    ll s1 = (keta < 2) ? 0 : max(i2 - 1, 0LL);
                    ll e1 = (keta < 2) ? 9 : min(i2 + 1, 9LL);
                    for (ll i1 = s1; !done && i1 <= e1; i1++) {
                      // for (ll i1 = 0; !done && i1 <= 9; i1++) {

                      // cout << i1 << endl;

                      ll num = i1 + i2 * 10LL + i3 * 100LL + i4 * 1000LL +
                               i5 * 10000LL + i6 * 100000LL + i7 * 1000000LL +
                               i8 * 10000000LL + i9 * 100000000LL +
                               i10 * 1000000000LL;

                      // cout << num << endl;
                      // cout << keta << endl;
                      bool runrun = num >= 1 &&
                                    (keta < 10 || abs(i10 - i9) <= 1) &&
                                    (keta < 9 || abs(i9 - i8) <= 1) &&
                                    (keta < 8 || abs(i8 - i7) <= 1) &&
                                    (keta < 7 || abs(i7 - i6) <= 1) &&
                                    (keta < 6 || abs(i6 - i5) <= 1) &&
                                    (keta < 5 || abs(i5 - i4) <= 1) &&
                                    (keta < 4 || abs(i4 - i3) <= 1) &&
                                    (keta < 3 || abs(i3 - i2) <= 1) &&
                                    (keta < 2 || abs(i2 - i1) <= 1);

                      if (runrun) {
                        count++;
                        // cout << num << endl;
                        if (count == K) {
                          ans = num;
                          done = true;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256