#include <bits/stdc++.h>
long long C[98][98], dp[16][98], k;
int t, num[16];
const char tohex[] = "0123456789abcdef";
inline void pre() {
  for (int i = 0; i < 98; i++) C[i][0] = 1;
  for (int i = 1; i < 98; i++)
    for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
}
inline long long solve(int len) {
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i <= num[0]; i++) dp[0][i] = C[len][i];
  for (int i = 1; i < 16; i++)
    for (int l = 0; l <= len; l++)
      for (int j = 0; j <= (((num[i]) < (l)) ? (num[i]) : (l)); j++)
        dp[i][l] += dp[i - 1][l - j] * C[len - l + j][j];
  return dp[15][len];
}
int main() {
  pre();
  scanf("%lld %d", &k, &t);
  for (register int i = 0; i < 16; i++) num[i] = t;
  register int len = 1;
  for (;; len++) {
    long long tmp = 0;
    if (len == 1)
      tmp = 15;
    else
      for (register int j = 1; j < 16; j++) {
        num[j]--;
        tmp += solve(len - 1);
        num[j]++;
      }
    if (k > tmp)
      k -= tmp;
    else
      break;
  }
  for (register int i = len; i > 0; i--) {
    if (i == 1) {
      for (register int j = 0; j < 16; j++) {
        if (!j && len == 1) continue;
        if (num[j]) k--;
        if (!k) {
          putchar(tohex[(j)]);
          break;
        }
      }
      break;
    }
    for (register int j = 0; j < 16; j++) {
      if (i == len && !j) continue;
      num[j]--;
      register long long tmp = solve(i - 1);
      if (k > tmp)
        k -= tmp;
      else {
        putchar(tohex[(j)]);
        break;
      }
      num[j]++;
    }
  }
  return 0;
}
