#include <bits/stdc++.h>
using namespace std;
const int N = 19;
long long INF = 2e9 + 19, A[N], dp[N][2], dpt[N][2], C[N][N];
inline long long Solve(int len, int w = -1) {
  if (!len) return 1LL;
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < 16; i++) {
    memset(dpt, 0, sizeof(dpt));
    for (int j = 0; j <= len; j++)
      for (int h = 0; j + h <= len && h <= A[i]; h++) {
        if (len > j)
          dpt[j + h][0] =
              min(dpt[j + h][0] + dp[j][0] * C[h][len - j - 1], INF);
        if (i > w && h > 0 && len > j)
          dpt[j + h][1] =
              min(dpt[j + h][1] + dp[j][0] * C[h - 1][len - j - 1], INF);
        if (i > w)
          dpt[j + h][1] = min(dpt[j + h][1] + dp[j][1] * C[h][len - j], INF);
      }
    memcpy(dp, dpt, sizeof(dp));
  }
  return (dp[len][1]);
}
int main() {
  long long K, T, len = 1;
  scanf("%lld%lld", &K, &T);
  for (int i = 0; i < N; i++)
    for (int j = C[0][i] = C[i][i] = 1; j < i; j++)
      C[j][i] = min(C[j - 1][i - 1] + C[j][i - 1], INF);
  for (int i = 0; i < N; i++) A[i] = T;
  for (; K > Solve(len, 0);) K -= Solve(len, 0), len++;
  long long rs = 0;
  for (int i = 1; i <= len; i++)
    for (int j = (i == 1); j < 16; j++)
      if (A[j] > 0) {
        A[j]--;
        long long vl = Solve(len - i, -1);
        if (vl < K)
          K -= vl, A[j]++;
        else
          rs = rs * 16 + j, j = 16;
      }
  return !printf("%llx", rs);
}
