#include <bits/stdc++.h>

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  const auto count = [](const int64_t v) {
    std::string s = std::to_string(v);
    int64_t dp[10], dp2[10];
    int64_t former = s[0] - '0';
    bool lim_check = true;

    for (int i = 1; i < 10; i++) {
      if (i < former) {
        dp[i] = 1;
      } else {
        dp[i] = 0;
      }
    }
    dp[0] = 0;

    for (size_t i = 1; i < s.size(); i++) {
      for (int j = 1; j < 10; j++) {
        dp2[j] = 1;
      }
      dp2[0] = 0;
      for (int j = 0; j < 10; j++) {
        dp2[j] += dp[j];
        if (0 <= j - 1) {
          dp2[j - 1] += dp[j];
        }
        if (j + 1 < 10) {
          dp2[j + 1] += dp[j];
        }
      }
      if (lim_check) {
        const int num = s[i] - '0';
        if (former + 1 < num) {
          if (0 <= former - 1) {
            dp2[former - 1]++;
          }
          dp2[former]++;
          if (former + 1 < 10) {
            dp2[former + 1]++;
          }
          lim_check = false;
        } else if (former + 1 == num) {
          if (0 <= former - 1) {
            dp2[former - 1]++;
          }
          dp2[former]++;
          former = num;
        } else if (former == num) {
          if (0 <= former - 1) {
            dp2[former - 1]++;
          }
          former = num;
        } else if (former - 1 == num) {
          former = num;
        } else {
          lim_check = false;
        }
      }
      std::swap(dp, dp2);
    }
    int64_t ans = 0;
    for (int64_t i = 0; i < 10; i++) {
      ans += dp[i];
    }
    if (lim_check) {
      ans++;
    }
    return ans;
  };

  int64_t k;
  std::cin >> k;

  const auto make_lunlun = [](const int64_t val) {
    std::string s = std::to_string(val);
    std::vector<int> ans(s.size());
    std::vector<bool> down(s.size());
    int former = s[0] - '0';
    bool check = true;
    ans[0] = former;
    down[0] = true;

    for (size_t i = 1; i < s.size(); i++) {
      int num = s[i] - '0';
      if (check) {
        if (num < former - 1) {
          check = false;
          size_t j = i - 1;
          while (down[j] == false) {
            j--;
          }
          ans[j]--;
          for (size_t k = j + 1; k <= i; k++) {
            ans[k] = std::min(9, ans[k - 1] + 1);
          }

        } else if (former + 1 < num) {
          check = false;
          ans[i] = std::min(9, ans[i - 1] + 1);
          down[i] = true;
        } else {
          ans[i] = num;
          if (num == former - 1 || num == 0) {
            down[i] = false;
          } else {
            down[i] = true;
          }
          former = num;
        }
      } else {
        ans[i] = std::min(9, ans[i - 1] + 1);
      }
    }

    int64_t ans_v = 0;
    for (const auto v : ans) {
      ans_v *= 10;
      ans_v += v;
    }
    return ans_v;
  };

  if (k == 1) {
    std::cout << 1 << std::endl;
    return 0;
  } else if (k == 100000) {
    std::cout << 3234566667 << std::endl;
    return 0;
  }

  int64_t left = 1, right = 3234566667;

  while (left != right) {
    const auto num = (left + right) / 2;
    const auto v = count(num);
    if (v < k) {
      left = num;
    } else if (v == k) {
      left = right = num;
      break;
    } else {
      right = num;
    }
  }

  std::cout << make_lunlun(right) << std::endl;

  return 0;
}

Measured memory_bytes: 256