#include <bits/stdc++.h>
using namespace std;
const int N = 24, M = 205;
long long C[M][M], f[N][N], lim[N], ans[N];
int k, t;
void init() {
  for (int i = 0; i <= M - 1; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
  }
}
long long solve1(int len) {
  memset(f, 0, sizeof f);
  f[0][0] = 1;
  for (int i = 0; i <= len; ++i)
    for (int j = 1; j <= 16; ++j) {
      for (int k = 0; k <= min(i * 1ll, lim[j - 1]); ++k) {
        f[i][j] += f[i - k][j - 1] * C[i][k];
      }
    }
  return f[len][16];
}
long long solve2(int len) {
  long long res = 0;
  for (int i = 0; i <= 15; ++i) lim[i] = t;
  for (int j = 1; j <= 15; ++j) {
    --lim[j];
    res += solve1(len - 1);
    ++lim[j];
  }
  return res;
}
int main() {
  init();
  int len;
  scanf("%d%d", &k, &t);
  for (int i = 0; i <= 15; ++i) lim[i] = t;
  for (len = 1;; ++len)
    if (k > solve2(len))
      k -= solve2(len);
    else
      break;
  for (int i = len; i >= 1; --i)
    for (int j = (len == i); j <= 15; ++j) {
      --lim[j];
      int cur = solve1(i - 1);
      if (cur >= k) {
        ans[i] = j;
        break;
      }
      k -= cur;
      ++lim[j];
    }
  for (int i = len; i >= 1; --i)
    if (ans[i] < 10)
      printf("%d", ans[i]);
    else
      printf("%c", ans[i] + 'a' - 10);
  return 0;
}
