#include <bits/stdc++.h>
using namespace std;
int k, t, w, num, a1, cnt[16];
char a[13];
long long tmp, C[25][25], f[25][25];
void dfs(int depth, bool youshu) {
  if (depth == w) {
    if (k <= num) {
      for (int i = 0; i < 16; i++)
        if (cnt[i] < t) {
          k--;
          if (k == 0) {
            a[depth] = (i < 10) ? i + 48 : i + 87;
            break;
          }
        }
    } else
      k -= num;
    return;
  }
  for (int i = youshu ^ 1; i < 16; i++)
    if (cnt[i] < t) {
      a[depth] = (i < 10) ? i + 48 : i + 87;
      cnt[i]++;
      if (cnt[i] == t) num--;
      dfs(depth + 1, 1);
      if (cnt[i] == t) num++;
      cnt[i]--;
      if (!k) return;
    }
}
inline long long power(long long x, int y) {
  long long z = 1;
  for (; y; y >>= 1, x *= x)
    if (y & 1) z *= x;
  return z;
}
long long F(int W, int S, int T) {
  unsigned long long ans = power(S, W), tjm = 1, fh = -1;
  for (int i = 1; i * (T + 1) <= W; i++, fh *= -1) {
    tjm *= C[W - (i - 1) * (T + 1)][T + 1];
    ans += 1ll * fh * C[S][i] * tjm * power(S, W - i * (T + 1));
  }
  return ans;
}
int main() {
  scanf("%d%d", &k, &t);
  num = 16;
  C[0][0] = 1;
  for (int i = 1; i <= 20; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  for (int i = 0; i <= 16; i++) f[0][i] = 1;
  for (int i = 1; i <= 10; i++)
    for (int j = 1; j <= 16; j++)
      for (int k = 0; k <= t; k++) f[i][j] += f[i - k][j - 1] * C[i][k];
  for (w = 1; w <= 9; w++) {
    tmp = f[w][16] / 16 * 15;
    if (k > tmp)
      k -= tmp;
    else
      break;
  }
  tmp = f[w - 1][16];
  if (w >= t + 1) tmp -= C[w - 1][t] * f[w - t - 1][15];
  a1 = (k - 1) / tmp + 1;
  a[1] = (a1 < 10) ? a1 + 48 : a1 + 87;
  cnt[a1]++;
  if (cnt[a1] == t) num--;
  k -= (a1 - 1) * tmp;
  if (w > 1) dfs(2, 1);
  for (int i = 1; i <= w; i++)
    if (a[i]) putchar(a[i]);
  puts("");
  return 0;
}
