#include <bits/stdc++.h>
using int_t = long long int;
constexpr int_t inf = 1000000000000000000;
int_t k;
int t;
int a[9];
int b[16];
int_t combination[9][9];
int_t dp[9][16];
int_t base[9];
int_t calc(int digits, int max_digit) {
  if (digits < 0) {
    return 1;
  }
  if (max_digit == 0) {
    if (t - b[0] >= digits) {
      return 1;
    } else {
      return 0;
    }
  }
  if (dp[digits][max_digit] >= 0) {
    return dp[digits][max_digit];
  }
  int_t result = 0;
  for (int i = 0; i <= std::min(digits, t - b[max_digit]); ++i) {
    result += combination[digits][i] * calc(digits - i, max_digit - 1);
  }
  dp[digits][max_digit] = result;
  return result;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cin >> k >> t;
  for (int_t i = 0; i < 9; ++i) {
    combination[i][0] = 1;
    for (int_t j = 1; j <= i; ++j) {
      combination[i][j] = combination[i - 1][j] + combination[i - 1][j - 1];
    }
  }
  base[0] = 0;
  for (int i = 1; i < 9; ++i) {
    for (int j = 1; j < 16; ++j) {
      ++b[j];
      std::fill(&dp[0][0], &dp[0][0] + sizeof(dp) / sizeof(**dp), -1);
      base[i] += calc(i - 1, 15);
      --b[j];
    }
    if (i >= 1) {
      base[i] += base[i - 1];
    }
  }
  int_t min = 1;
  int_t max = (1LL << 36) - 1;
  while (min < max) {
    int_t m = (min + max) / 2;
    int_t p = m + 1;
    int digit_count = 0;
    for (int i = 0; i < 9 && p > 0; ++i) {
      a[i] = p % 16;
      p /= 16;
      digit_count = i;
    }
    int_t count = base[digit_count];
    std::fill(b, b + sizeof(b) / sizeof(*b), 0);
    for (int i = digit_count; i >= 0; --i) {
      for (int j = (i == digit_count ? 1 : 0); j < a[i]; ++j) {
        ++b[j];
        std::fill(&dp[0][0], &dp[0][0] + sizeof(dp) / sizeof(**dp), -1);
        count += calc(i, 15);
        --b[j];
      }
      ++b[a[i]];
      if (b[a[i]] > t) {
        break;
      }
    }
    if (count >= k) {
      max = m;
    } else {
      min = m + 1;
    }
  }
  std::vector<int> result;
  while (min > 0) {
    result.emplace_back(min % 16);
    min /= 16;
  }
  for (auto iter = result.rbegin(); iter != result.rend(); ++iter) {
    int digit = *iter;
    if (digit < 10) {
      std::cout << digit;
    } else {
      std::cout << char('a' + (digit - 10));
    }
  }
  std::cout << '\n';
  return 0;
}
