#include <bits/stdc++.h>
using namespace std;
namespace WHH {
int K, T, len;
int lmt[16];
char dic[16];
long long C[205][205], dp[25][205];
template <typename _T>
_T Min(_T a, _T b) {
  return a > b ? b : a;
}
inline void init() {
  C[0][0] = 1;
  for (int i = 1; i <= 200; i++) {
    C[i][0] = 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 < 10; i++) dic[i] = '0' + i;
  for (int i = 10; i < 16; i++) dic[i] = 'a' + i - 10;
}
inline void getlen() {
  for (len = 1;; len++) {
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < Min(len, T + 1); i++) dp[0][i] = C[len - 1][i];
    for (int i = 1; i < 16; i++)
      for (int j = 0; j <= len; j++)
        for (int k = 0; k <= Min(j, T); k++)
          dp[i][j] += dp[i - 1][j - k] * C[len - (j - k)][k];
    if (dp[15][len] >= K) break;
    K -= dp[15][len];
  }
}
inline void solve() {
  for (int i = 0; i < 16; i++) lmt[i] = T;
  for (int clen = len; clen >= 1; clen--) {
    int st = 0 + (clen == len);
    for (int i = st; i < 16; i++) {
      if (!lmt[i]) continue;
      memset(dp, 0, sizeof dp);
      lmt[i]--;
      for (int j = 0; j < 16; j++)
        for (int cclen = 0; cclen < clen; cclen++)
          for (int k = 0; k <= Min(cclen, lmt[j]); k++) {
            int coef;
            if (!j)
              coef = 0 + (k == cclen);
            else
              coef = dp[j - 1][cclen - k];
            dp[j][cclen] += coef * C[clen - 1 - (cclen - k)][k];
          }
      if (dp[15][clen - 1] >= K) {
        putchar(dic[i]);
        break;
      }
      K -= dp[15][clen - 1];
      lmt[i]++;
    }
  }
}
int work() {
  scanf("%d%d", &K, &T);
  init();
  getlen();
  solve();
  return 0;
}
}  // namespace WHH
int main() { return WHH::work(); }
