#include <bits/stdc++.h>
using namespace std;
const int Hex = 16;
int read() {
  int x = 0, f = 1;
  char s;
  while ((s = getchar()) > '9' || s < '0')
    if (s == '-') f = -1;
  while (s >= '0' && s <= '9')
    x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();
  return x * f;
}
int K, t, n, lim[20];
long long C[105][105], dp[20][105];
char dic[20] = {'0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
void init() {
  C[0][0] = 1;
  for (int i = 1; i <= 100; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
}
void DP1() {
  for (n = 1;; ++n) {
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < min(n, t + 1); ++i) dp[0][i] = C[n - 1][i];
    for (int i = 1; i < Hex; ++i)
      for (int j = 0; j <= n; ++j)
        for (int k = 0; k <= min(t, j); ++k)
          dp[i][j] += dp[i - 1][j - k] * C[n - (j - k)][k];
    if (dp[Hex - 1][n] >= K) break;
    K -= dp[Hex - 1][n];
  }
}
void DP2() {
  long long tmp;
  for (int i = 0; i < Hex; ++i) lim[i] = t;
  for (int len = n; len; --len) {
    int down = (len == n);
    for (int num = down; num < Hex; ++num) {
      if (!lim[num]) continue;
      --lim[num];
      memset(dp, 0, sizeof dp);
      for (int i = 0; i < Hex; ++i)
        for (int j = 0; j < len; ++j)
          for (int k = 0; k <= min(lim[i], j); ++k) {
            if (!i) {
              if (k == j)
                tmp = 1;
              else
                tmp = 0;
            } else
              tmp = dp[i - 1][j - k];
            dp[i][j] += tmp * C[len - 1 - (j - k)][k];
          }
      if (dp[Hex - 1][len - 1] >= K) {
        putchar(dic[num]);
        break;
      }
      K -= dp[Hex - 1][len - 1];
      ++lim[num];
    }
  }
}
int main() {
  K = read(), t = read();
  init();
  DP1();
  DP2();
  return 0;
}
