#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;
using uint64 = unsigned long long;
using int128 = __int128_t;
using uint128 = __uint128_t;
using float64 = long double;

template <typename T = int>
struct Range {
  struct RangeIterator {
    T i, step;

    RangeIterator(T i, T step) : i{i}, step{step} {}

    T &operator*() { return i; }
    RangeIterator &operator++() {
      i += step;
      return *this;
    }
    bool operator!=(const RangeIterator &rhs) const {
      return (step > 0 && i < rhs.i) || (step < 0 && i > rhs.i);
    }
  };

  T start, stop, step;

  Range(T start, T stop, T step) : start{start}, stop{stop}, step{step} {}
  Range(T start, T stop) : Range(start, stop, 1) {}
  Range(T stop) : Range(0, stop, 1) {}

  RangeIterator begin() const { return RangeIterator{start, step}; }
  RangeIterator end() const { return RangeIterator{stop, step}; }
};

template <typename T>
inline void ChooseMax(T &a, const T &b) {
  a = std::max(a, b);
}

template <typename T>
inline void ChooseMin(T &a, const T &b) {
  a = std::min(a, b);
}

template <typename T>
std::ostream& operator<<(std::ostream& ostr, const std::vector<T>& vec) {
  ostr << "[";
  for (auto itr = vec.begin(); itr != vec.end(); itr++) {
    if (itr != vec.begin()) {
      ostr << ", ";
    }
    ostr << *itr;
  }
  ostr << "]";
  return ostr;
}

template <typename K, typename V>
std::ostream& operator<<(std::ostream& ostr, const std::map<K, V>& map) {
  ostr << "{";
  for (auto itr = map.begin(); itr != map.end(); itr++) {
    if (itr != map.begin()) {
      ostr << ", ";
    }
    ostr << itr->first << " => " << itr->second;
  }
  ostr << "}";
  return ostr;
}

template <typename T>
std::ostream& operator<<(std::ostream& ostr, const std::set<T>& set) {
  ostr << "{";
  for (auto itr = set.begin(); itr != set.end(); itr++) {
    if (itr != set.begin()) {
      ostr << ", ";
    }
    ostr << *itr;
  }
  ostr << "}";
  return ostr;
}

template <typename F, typename S>
std::ostream& operator<<(std::ostream& ostr, const std::pair<F, S>& pair) {
  ostr << "(" << pair.first << ", " << pair.second << ")";
  return ostr;
}

void SolveProblem() {
  int k;
  std::cin >> k;

  std::vector<int64> numbers;
  for (int d = 1; d <= 9; d++) {
    numbers.push_back(d);
  }
  int idx = 0;
  while (numbers.size() < k) {
    int64 num = numbers[idx++];
    int d = num % 10;

    for (int nd = d - 1; nd <= d + 1; nd++) {
      if (nd < 0 || nd > 9) continue;
      numbers.push_back(num * 10 + nd % 10);
    }
  }

  /*
  for (int64 num : numbers) {
    std::cerr << num << std::endl;
  }
  */

  std::cout << numbers[k - 1] << std::endl;
}

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

  std::cout.setf(std::ios::fixed);
  std::cout.precision(10);

  SolveProblem();

  return 0;
}


Measured memory_bytes: 1400