/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-06 14:23:18
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int k; cin >> k;

  binary_heap<int64> pq;

  for (int64 i = 1; i < 10; ++i) pq.emplace(i);

  vector<int64> ans;

  for (int64 i = 1; i < 10; ++i) ans.emplace_back(i);

  while ((int) ans.size() < k) {
    int64 cur = pq.top(); pq.pop();
    char c = to_string(cur).back();
    int64 pre = c - '0' - 1;
    int64 now = c - '0';
    int64 nxt = c - '0' + 1;
    if (c == '0') {
      ans.emplace_back(cur * 10 + now); pq.emplace(cur * 10 + now);
      if ((int) ans.size() < k) {
        ans.emplace_back(cur * 10 + nxt);
        pq.emplace(cur * 10 + nxt);
      }
    } else if (c == '9') {
      ans.emplace_back(cur * 10 + pre); pq.emplace(cur * 10 + pre);
      if ((int) ans.size() < k) {
        ans.emplace_back(cur * 10 + now);
        pq.emplace(cur * 10 + now);
      }
    } else {
      ans.emplace_back(cur * 10 + pre); pq.emplace(cur * 10 + pre);
      if ((int) ans.size() < k) {
        ans.emplace_back(cur * 10 + now);
        pq.emplace(cur * 10 + now);
      }
      if ((int) ans.size() < k) {
        ans.emplace_back(cur * 10 + nxt);
        pq.emplace(cur * 10 + nxt);
      }
    }
  }

  //debug(ans);

  cout << ans[k - 1] << endl;

  return 0;
}

Measured memory_bytes: 2288