#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, t = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') t = -1;
    c = getchar();
  }
  while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
  return s * t;
}
const int N = 1e5 + 5;
inline void Min(int &x, int v) {
  if (v < x) x = v;
}
long long F[2][15], fac[15] = {1};
int k, t, n, num[16], ans[15];
inline long long Q2() {
  int now = 1, pre = 0;
  memset(F, 0, sizeof(F));
  F[now][0] = fac[n];
  for (register int i = 0; i <= 15; i++) {
    if (num[i] == t) continue;
    swap(now, pre);
    for (register int j = 0; j <= n; j++) F[now][j] = 0;
    for (register int j = 0; j <= t - num[i]; j++) {
      for (register int k = 0; k <= n - j; k++) {
        F[now][k + j] += F[pre][k] / fac[j];
      }
    }
  }
  return F[now][n];
}
inline long long Q(int x) {
  n = x - 1, memset(num, 0, sizeof(num)), num[1]++;
  return Q2() * 15;
}
int main() {
  k = read(), t = read();
  for (register int i = 1; i <= 14; i++) fac[i] = fac[i - 1] * i;
  int tot = 1, w;
  long long cnt;
  while ((cnt = Q(tot)) < k) k -= cnt, tot++;
  w = k / (cnt / 15), k %= (cnt / 15);
  if (!k) k += (cnt / 15), w--;
  memset(num, 0, sizeof(num));
  ans[1] = w + 1, num[w + 1]++;
  for (register int i = 2; i <= tot; i++) {
    for (register int j = 0; j <= 15; j++) {
      if (num[j] == t) continue;
      num[j]++, n = tot - i;
      if ((cnt = Q2()) < k)
        k -= cnt;
      else {
        ans[i] = j;
        break;
      }
      num[j]--;
    }
  }
  for (register int i = 1; i <= tot; i++) {
    if (ans[i] <= 9)
      putchar('0' + ans[i]);
    else
      putchar('a' + ans[i] - 10);
  }
  puts("");
  return 0;
}
