#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
long long K, T;
long long C[10][10];
signed main() {
  for (long long i = 0; i < (10); i++) {
    C[i][0] = C[i][i] = 1;
    for (long long j = 1; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  }
  cin >> K >> T;
  long long cnt[16];
  for (long long i = 0; i < (1 << 20); i++) {
    memset(cnt, 0, sizeof(cnt));
    bool ex = false;
    for (long long j = 4; j >= 0; j--) {
      long long t = i >> (4 * j) & 15;
      if (ex || t) cnt[t]++;
      if (t) ex = true;
    }
    bool ok = true;
    for (long long j = 0; j < (16); j++)
      if (cnt[j] > T) ok = false;
    if (ok) {
      if (K == 0) {
        printf("%llx\n", i);
        return 0;
      }
      K--;
    }
  }
  long long dp[20][6];
  long long tar;
  for (long long i = 1; i < (1 << 16); i++) {
    memset(cnt, 0, sizeof(cnt));
    bool ex = false;
    for (long long j = 3; j >= 0; j--) {
      long long t = i >> (4 * j) & 15;
      if (ex || t) cnt[t]++;
      if (t) ex = true;
    }
    bool ok = true;
    for (long long j = 0; j < (16); j++)
      if (cnt[j] > T) ok = false;
    if (!ok) continue;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (long long j = 0; j < 16; j++) {
      for (long long k = 0; k <= 5; k++) {
        for (long long l = 0; k + l <= 5 && cnt[j] + l <= T; l++) {
          dp[j + 1][k + l] += dp[j][k] * C[5 - k][l];
        }
      }
    }
    if (K < dp[16][5]) {
      tar = i;
      break;
    }
    K -= dp[16][5];
  }
  for (long long i = 0; i < (1 << 20); i++) {
    long long d = (tar << 20) + i;
    memset(cnt, 0, sizeof(cnt));
    bool ex = false;
    for (long long j = 8; j >= 0; j--) {
      long long t = d >> (4 * j) & 15;
      if (ex || t) cnt[t]++;
      if (t) ex = true;
    }
    bool ok = true;
    for (long long j = 0; j < (16); j++)
      if (cnt[j] > T) ok = false;
    if (ok) {
      if (K == 0) {
        printf("%llx\n", d);
        return 0;
      }
      K--;
    }
  }
  return 0;
}
