#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 10000020;
int bufpos;
char buf[MAXSIZE];
void init() {
  buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
  bufpos = 0;
}
int readint() {
  int val = 0;
  for (; !isdigit(buf[bufpos]); bufpos++)
    ;
  for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] - '0';
  return val;
}
char readchar() {
  for (; isspace(buf[bufpos]); bufpos++)
    ;
  return buf[bufpos++];
}
int readstr(char* s) {
  int cur = 0;
  for (; isspace(buf[bufpos]); bufpos++)
    ;
  for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];
  s[cur] = '\0';
  return cur;
}
char gt(int x) { return x <= 9 ? x + '0' : 'a' + x - 10; }
long long dp[63];
long long c[63][63];
long long work(int l, int* a) {
  for (int i = 1; i <= l; i++) dp[i] = 0;
  dp[0] = 1;
  for (int i = 0; i < 16; i++)
    for (int j = l; j >= 1; j--)
      for (int k = 1; k <= min(a[i], j); k++) dp[j] += dp[j - k] * c[j][k];
  return dp[l];
}
int main() {
  init();
  c[0][0] = 1;
  for (int i = 1; i <= 60; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  }
  long long k = readint();
  int t = readint();
  long long sum = 0;
  int to = 0, qwq[16];
  for (int i = 0; i < 16; i++) qwq[i] = t;
  for (int i = 1; i <= 60; i++) {
    qwq[0]--;
    long long now = 15 * work(i - 1, qwq);
    qwq[0]++;
    if (sum + now >= k) {
      k -= sum;
      to = i;
      break;
    }
    sum += now;
  }
  for (int i = to; i; i--) {
    for (int j = i != to ? 0 : 1; j < 16; j++) {
      if (!qwq[j]) continue;
      qwq[j]--;
      long long now = work(i - 1, qwq);
      if (k <= now) {
        putchar(gt(j));
        break;
      }
      k -= now;
      qwq[j]++;
    }
  }
}
