#include <bits/stdc++.h>
using namespace std;
int n, k;
int ai[20];
long long f[20][20];
long long fac[20];
int as[20];
long long C(int a, int b) { return fac[a] / fac[b] / fac[a - b]; }
int total;
long long get(int l) {
  for (int i = 0; i < (int)(17); i++) {
    for (int j = 0; j < (int)(l + 1); j++) {
      f[i][j] = 0;
    }
  }
  f[0][0] = 1;
  for (int i = 0; i < (int)(16); i++) {
    for (int j = 0; j < (int)(ai[i] + 1); j++) {
      for (int k = 0; k < (int)(l - j + 1); k++) {
        f[i + 1][j + k] += f[i][k] * C(k + j, j);
      }
    }
  }
  return f[16][l];
}
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  n--;
  fac[0] = 1;
  for (int i = (int)(1); i < (int)(17); i++) {
    fac[i] = fac[i - 1] * i;
  }
  for (int i = 0; i < (int)(16); i++) ai[i] = k;
  total = 1;
  ai[0]--;
  while (true) {
    long long p = get(total - 1) * 15;
    if (n >= p) {
      n -= p;
      total++;
    } else
      break;
  }
  ai[0]++;
  int temp_total = total;
  while (total) {
    for (int i = total == temp_total; i < 16; i++) {
      if (ai[i]) {
        ai[i]--;
        long long p = get(total - 1);
        if (n >= p) {
          n -= p;
        } else {
          as[total] = i;
          break;
        }
        ai[i]++;
      }
    }
    total--;
  }
  for (int i = temp_total; i >= 1; i--) {
    if (as[i] >= 10) {
      printf("%c", as[i] - 10 + 'a');
    } else {
      printf("%d", as[i]);
    }
  }
  return 0;
}
