#include <bits/stdc++.h>
const long long D = 16, C = 101;
long long cn[C][C], pw[20][20];
void newton(long long f) {
  long long i = 1, j = 1;
  cn[0][0] = 1;
  for (i = 1; i <= f; i++) {
    cn[i][0] = 1;
    for (j = 1; j <= i; j++) cn[i][j] = (cn[i - 1][j - 1] + cn[i - 1][j]);
  }
}
long long dp[D][D];
long long decipher(long long n, long long d[]) {
  long long i = 0, j = 0, ij = 0, ji = 0;
  long long wynn = 0, sgn = 1;
  dp[0][0] = 1;
  for (i = 0; i < D; i++) {
    for (j = D - 1; j > 0; j--) {
      for (ij = D - 1; ij >= d[i]; ij--) {
        for (ji = 0; ij - d[i] - ji >= 0; ji++) {
          dp[j][ij] += dp[j - 1][ij - d[i] - ji] * cn[ij][d[i] + ji];
        }
      }
    }
  }
  for (i = 0; i < D; i++) {
    if (i % 2 == 0)
      sgn = 1;
    else
      sgn = -1;
    for (j = 0; j < D; j++) {
      wynn = wynn + sgn * dp[i][j] * cn[n][j] * pw[16 - i][n - j];
      dp[i][j] = 0;
    }
  }
  return wynn;
}
long long cf[20], res[20];
int main() {
  long long k, lc = 1, wt = 0, lst = 0, j, i, t;
  for (i = 0; i < 17; i++) pw[i][0] = 1;
  for (j = 0; j < 17; j++)
    for (i = 1; i < 15; i++) pw[j][i] = (pw[j][i - 1] * j);
  newton(17);
  scanf("%lld %lld", &k, &t);
  for (i = 0; i < D; i++) cf[i] = t + 1;
  for (lc = 1; lc < 15; lc++) {
    for (i = 1; i < D; i++) {
      cf[i]--;
      wt += decipher(lc - 1, cf);
      cf[i]++;
    }
    if (wt >= k) break;
    lst = wt;
  }
  wt = 0;
  k -= lst;
  for (i = 0; i < lc; i++) {
    for (j = 0; j < D; j++) {
      if (cf[j] == 1 || (i == 0 && j == 0)) continue;
      cf[j]--;
      wt = decipher(lc - i - 1, cf);
      if (wt >= k) {
        res[i] = j;
        break;
      }
      k -= wt, cf[j]++;
    }
  }
  for (i = 0; i < lc; i++) {
    if (res[i] < 10)
      printf("%d", res[i]);
    else
      putchar(res[i] - 10 + 97);
  }
  return 0;
}
