#include <bits/stdc++.h>
long long k;
int t;
long long C[16][16];
const double INF = 1e12;
const char hex[] = "0123456789abcdef";
long long count(int st[], int d, bool zero = true) {
  if (d == 0) return 1;
  long long dp[17][17];
  double est[17][17];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < 17; i++) est[0][i] = 0;
  dp[0][0] = 1;
  est[0][0] = 1;
  for (int i = 1; i < 16; i++)
    for (int j = 0; j <= d; j++) {
      est[i][j] = 0;
      for (int k = 0; k <= st[i] && k <= j; k++) {
        dp[i][j] += C[j][k] * dp[i - 1][j - k];
        est[i][j] += C[j][k] * est[i - 1][j - k];
      }
    }
  if (zero) {
    est[16][d] = 0;
    for (int i = 0; i <= st[0] && i <= d; i++) {
      dp[16][d] += C[d][i] * dp[15][d - i];
      est[16][d] += C[d][i] * est[15][d - i];
    }
  } else {
    est[16][d] = 0;
    for (int i = 0; i <= st[0] && i < d; i++) {
      dp[16][d] += C[d - 1][i] * dp[15][d - i];
      est[16][d] += C[d - 1][i] * est[15][d - i];
    }
  }
  return est[16][d] >= INF ? k + 100 : dp[16][d];
}
int solve(int ans[]) {
  int st[16];
  int first;
  for (int i = 0; i < 16; i++) st[i] = t;
  for (first = 1; first <= 10; first++) {
    long long tmp = count(st, first, false);
    if (tmp >= k) break;
    k -= tmp;
  }
  for (int i = 0; i < first && k > 0; i++) {
    int cur = i == 0 ? 1 : 0;
    for (; cur < 16; cur++) {
      if (st[cur] == 0) continue;
      st[cur]--;
      long long tmp = count(st, first - i - 1);
      st[cur]++;
      if (tmp >= k) break;
      k -= tmp;
    }
    st[cur]--;
    ans[i] = cur;
  }
  return 0;
}
void pre() {
  C[0][0] = 1;
  for (int i = 1; i <= 10; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
}
int main() {
  pre();
  scanf("%I64d %d", &k, &t);
  int ans[16];
  memset(ans, -1, sizeof(ans));
  solve(ans);
  for (int i = 0; ans[i] >= 0; i++) printf("%c", hex[ans[i]]);
  puts("");
  return 0;
}
