#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void next_int(T &x) {
  x = 0;
  char c;
  bool neg = false;
  while (!isdigit(c = getchar()))
    if (c == '-') neg = true;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
  if (neg) x = -x;
}
template <typename T>
inline void write_int(T x) {
  if (x > 9) write_int(x / 10);
  putchar(x % 10 + 48);
}
const long long oo = 2e9 + 7;
long long k, dp[20][25], C[25][25];
int t, cnt[20];
inline char tohex(int x) {
  if (x < 10) return x + '0';
  return 'a' + x - 10;
}
void init() {
  for (int i = (0); i <= (20); ++i) C[i][0] = 1;
  for (int i = (1); i <= (20); ++i)
    for (int j = (1); j <= (i); ++j) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      if (C[i][j] > oo) C[i][j] = oo;
    }
}
inline long long mult(const long long &x, const long long &y) {
  long long tmp = x * y;
  return min(tmp, oo);
}
inline long long DP(int len) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = (0); i < (16); ++i)
    for (int j = (0); j < (len + 1); ++j)
      if (dp[i][j] > 0)
        for (int k = (0); k < (cnt[i] + 1); ++k)
          if (j + k <= len) {
            dp[i + 1][j + k] += mult(dp[i][j], C[j + k][k]);
            if (dp[i + 1][j + k] > oo) dp[i + 1][j + k] = oo;
          }
  return dp[16][len];
}
int main() {
  next_int(k), next_int(t);
  for (int i = (0); i < (16); ++i) cnt[i] = t;
  init();
  int diglen = 1;
  while (true) {
    long long val = 0;
    for (int i = (1); i < (16); ++i)
      if (cnt[i] > 0) {
        --cnt[i];
        val += DP(diglen - 1);
        ++cnt[i];
        if (val > oo) val = oo;
      }
    if (val < k)
      k -= val, ++diglen;
    else
      break;
  }
  for (int i = (diglen + 1) - 1; i >= (1); --i) {
    for (int j = ((i == diglen ? 1 : 0)); j < (16); ++j)
      if (cnt[j] > 0) {
        --cnt[j];
        long long val = DP(i - 1);
        if (val < k)
          k -= val, ++cnt[j];
        else {
          putchar(tohex(j));
          break;
        }
      }
  }
  return 0;
}
