#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
const long long N = 205;
long long K, t, C[N][N];
inline void init() {
  K = read();
  t = read();
  for (long long i = 0; i < N; i++) {
    C[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
  }
}
long long dp[18][N], L, ton[18];
inline long long solve(long long len) {
  memset(dp, 0, sizeof dp);
  for (long long i = 0; i <= ton[0]; i++) dp[0][i] = C[len][i];
  for (long long i = 1; i < 16; i++) {
    for (long long j = 0; j <= len; j++) {
      for (long long k = 0; k <= min(ton[i], j); k++) {
        dp[i][j] += dp[i - 1][j - k] * C[len - j + k][k];
      }
    }
  }
  return dp[15][len];
}
inline void print(long long x) {
  if (x < 10)
    putchar(x + '0');
  else
    putchar(x - 10 + 'a');
}
long long num[N];
inline void solve() {
  for (long long i = 0; i < 16; i++) ton[i] = t;
  L = 1;
  while (1) {
    long long tmp = 0;
    if (L == 1)
      tmp = 15;
    else {
      for (long long j = 1; j < 16; j++) {
        ton[j]--;
        tmp += solve(L - 1);
        ton[j]++;
      }
    }
    if (K > tmp)
      K -= tmp;
    else
      break;
    L++;
  }
  for (long long i = L; i; i--) {
    if (i == 1) {
      for (long long j = 0; j < 16; j++) {
        if (L == 1 && j == 0) continue;
        if (ton[j]) K--;
        if (!K) {
          print(j);
          break;
        }
      }
      break;
    }
    for (long long j = 0; j < 16; j++) {
      if (i == L && j == 0) continue;
      ton[j]--;
      long long tmp = solve(i - 1);
      if (tmp < K)
        K -= tmp;
      else {
        print(j);
        break;
      }
      ton[j]++;
    }
  }
}
signed main() {
  init();
  solve();
  return 0;
}
