#include <bits/stdc++.h>
using namespace std;
long long n, t, len;
long long dir[20], lim[20];
long long C[20][20], dp[20][20];
void init() {
  for (long long i = 0; i < 16; i++) {
    C[i][0] = 1;
    for (long long j = 1; j <= i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  }
  for (long long i = 0; i < 10; i++) dir[i] = i + '0';
  for (long long i = 10; i < 16; i++) dir[i] = i - 10 + 'a';
}
void GetLen() {
  for (len = 1;; len++) {
    memset(dp, 0, sizeof(dp));
    for (long long i = 0; i < min(len, t + 1); i++) dp[0][i] = C[len - 1][i];
    for (long long i = 1; i < 16; i++)
      for (long long j = 0; j <= len; j++)
        for (long long k = 0; k <= min(j, t); k++)
          dp[i][j] += dp[i - 1][j - k] * C[len - (j - k)][k];
    if (dp[15][len] >= n)
      break;
    else
      n -= dp[15][len];
  }
}
void solve() {
  for (long long i = 0; i < 16; i++) lim[i] = t;
  for (long long Len = len; Len; Len--) {
    for (long long i = 0 + (Len == len); i < 16; i++) {
      if (!lim[i]) continue;
      memset(dp, 0, sizeof(dp));
      lim[i]--;
      long long temp = 0;
      for (long long j = 0; j < 16; j++)
        for (long long newlen = 0; newlen <= Len - 1; newlen++)
          for (long long k = 0; k <= min(lim[j], newlen); k++) {
            if (!j)
              if (k == newlen)
                temp = 1;
              else
                temp = 0;
            else
              temp = dp[j - 1][newlen - k];
            dp[j][newlen] += temp * C[Len - 1 - (newlen - k)][k];
          }
      if (dp[15][Len - 1] >= n) {
        printf("%c", dir[i]);
        break;
      }
      n -= dp[15][Len - 1];
      lim[i]++;
    }
  }
}
signed main() {
  scanf("%d %d", &n, &t);
  init();
  GetLen();
  solve();
  return 0;
}
