#include <bits/stdc++.h>
using namespace std;
const long long N = 16;
const char b16[] = "0123456789abcdef";
long long C[N + 1][N + 1], f[N + 1][N + 1];
long long n, a[N + 1];
void init() {
  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];
  }
}
inline long long c(long long n, long long k) {
  if (n < 0 || k < 0 || k > n) return 0;
  return C[n][k];
}
void get(long long L) {
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (long long i = 1; i <= N; ++i)
    for (long long j = 0; j <= L; ++j) {
      for (long long k = 0; k <= min(j, a[i == N ? 0 : i]); ++k)
        f[i][j] += c(j - (i == N), k) * f[i - 1][j - k];
      ("f[%d][%d] = %lld\n", i, j, f[i][j]);
    }
  {
    f[0][0] = 0;
    for (long long j = 0; j <= L; ++j) {
      for (long long k = 0; k <= min(j, a[0]); ++k)
        f[0][j] += c(j, k) * f[N - 1][j - k];
      ("f[0][%d] = %lld\n", j, f[0][j]);
    }
  }
}
string solve(long long k, long long t) {
  long long len = 0, sum = 0;
  string ans;
  for (long long i = 0; i <= N; ++i) a[i] = t;
  get(N);
  for (len = 1; (sum += f[N][len]) < k; ++len)
    ;
  sum -= f[N][len];
  ("sum=%d\n", sum);
  for (long long i = len; i; --i) {
    for (long long j = (i == len); j < N; ++j)
      if (a[j ? j : N]) {
        a[j]--;
        get(i - 1);
        ("%d:%d %lld\n", j, sum, f[0][i - 1]);
        if (sum + f[0][i - 1] >= k) {
          ans += b16[j];
          break;
        }
        sum += f[0][i - 1];
        a[j]++;
      }
  }
  return ans;
}
long long test() {
  for (long long i = 1; i <= 105; ++i) {
    cout << i << ':' << solve(i, 1) << endl;
  }
  return 0;
}
signed main() {
  init();
  long long k, t;
  cin >> k >> t;
  cout << solve(k, t) << endl;
}
