#include <bits/stdc++.h>
using namespace std;
const long long B = 20, m = 16;
long long k, t, jc[B], shu[B], f[B][B], dep;
inline long long C(long long n, long long m) {
  return jc[n] / jc[m] / jc[n - m];
}
inline void pre() {
  long long i;
  jc[0] = 1;
  for (i = 1; i <= m; i++) jc[i] = 1LL * jc[i - 1] * i;
  for (i = 1; i <= m; i++) shu[i] = t;
}
inline long long get(long long up) {
  long long i, j, k;
  for (i = 0; i <= m; i++) f[0][i] = 1;
  for (i = 1; i <= up; i++) {
    for (j = 1; j <= m; j++) {
      f[i][j] = 0;
      for (k = 0; k <= min(i, shu[j]); k++)
        f[i][j] += f[i - k][j - 1] * C(i, k);
    }
  }
  return f[up][m];
}
inline void dfs(long long now, long long sum) {
  long long i, sz;
  if (!now) return;
  for (i = ((now == dep) ? 2 : 1); i <= 16; i++)
    if (shu[i]) {
      shu[i]--;
      sz = get(now - 1);
      if (sz >= sum) {
        i--;
        if (i <= 9)
          putchar((char)i + '0');
        else
          putchar((char)i - 10 + 'a');
        dfs(now - 1, sum);
        break;
      }
      shu[i]++;
      sum -= sz;
    }
}
signed main() {
  long long i, sz;
  scanf("%lld%lld", &k, &t);
  dep = 1;
  pre();
  for (;;) {
    shu[2]--;
    sz = get(dep - 1) * 15;
    shu[2]++;
    if (sz >= k) break;
    dep++;
    k -= sz;
  }
  dfs(dep, k);
}
