#include using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; int power(i64 a, i64 b) { i64 res = 1; for (; b; b /= 2, a = 1LL * a * a) { if (b % 2) { res = 1LL * res * a; } } return res; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); i64 n, k; std::cin >> n >> k; std::vector f; while (n) { f.push_back(n % 10); n /= 10; } std::reverse(f.begin(), f.end()); std::vector nums, ans; auto dfs = [&](auto&& self, int dep) -> void { if (dep == f.size()) { i64 cur = 0; // for (int x : nums) std::cout << x << " "; // std::cout << '\n'; for (int x : nums) { cur = cur * 10LL + x; } ans.push_back(cur); return ; } for (int i = 0; i <= f[dep]; i++) { nums.push_back(i); self(self, dep + 1); nums.pop_back(); } }; dfs(dfs, 0); std::sort(ans.begin(), ans.end()); // for (i64 x : ans) std::cout << x << " "; std::cout << ans[--k] << '\n'; return 0; }