#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
namespace IO {
const int L = 1 << 15;
char ibuf[L | 1], *iS = ibuf, *iT = ibuf, obuf[L | 1], *oS = obuf,
                  *oT = obuf + L, c, st[66];
int tp = 0, f;
inline char gc() {
  if (iS == iT) iT = (iS = ibuf) + fread(ibuf, sizeof(char), L, stdin);
  return (*iS++);
}
inline void flush() {
  fwrite(obuf, sizeof(char), oS - obuf, stdout);
  oS = obuf;
}
inline void pc(char c) {
  *oS++ = c;
  if (oS == oT) flush();
}
inline long long read() {
  long long x = 0;
  f = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c & 15);
  return x * f;
}
inline void write(long long x) {
  if (!x) putchar('0');
  if (x < 0) putchar('-'), x = -x;
  while (x) st[++tp] = x % 10 + '0', x /= 10;
  while (tp) putchar(st[tp--]);
}
inline void writeln(long long x) {
  write(x);
  putchar('\n');
}
inline void wri(long long x) { write(x), putchar(' '); }
struct IOflusher {
  ~IOflusher() { flush(); }
} _ioflusher_;
}  // namespace IO
using IO::read;
using IO::wri;
long long k, t, deep;
long long C[20][20], f[20][20];
int a[23], num[20], dep;
long long dp(int x) {
  for (register int i = (0); i <= int(16); ++i) f[0][i] = 1;
  for (register int i = (1); i <= int(x); ++i) {
    for (register int j = (1); j <= int(16); ++j) {
      f[i][j] = 0;
      for (register int k = (0); k <= int(min(i, a[j])); ++k) {
        f[i][j] += f[i - k][j - 1] * C[i][k];
      }
    }
  }
  return f[x][16];
}
void dfs(int k, int x) {
  if (x == 0) return;
  int limitl = (x == dep) ? 2 : 1;
  for (register int i = (limitl); i <= int(16); ++i) {
    if (!a[i]) continue;
    a[i]--;
    long long sz = dp(x - 1);
    if (sz >= k) {
      if (i - 1 >= 10) {
        printf("%c", i - 1 + 'a' - 10);
      } else {
        printf("%d", i - 1);
      }
      dfs(k, x - 1);
      break;
    }
    k -= sz;
    a[i]++;
  }
}
int main() {
  k = read(), t = read();
  for (register int i = (1); i <= int(16); ++i) a[i] = t;
  C[0][0] = 1;
  for (register int i = (1); i <= int(10); ++i) {
    C[i][0] = 1;
    for (register int j = (1); j <= int(i); ++j)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
  }
  dep = 1;
  while (true) {
    a[2]--;
    long long sz = dp(dep - 1) * 15;
    a[2]++;
    if (sz >= k) break;
    dep++;
    k -= sz;
  }
  dfs(k, dep);
  return 0;
}
