#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void minimize(X &x, const Y &y) {
  if (x > y) x = y;
}
template <class X, class Y>
void maximize(X &x, const Y &y) {
  if (x < y) x = y;
}
template <class T>
T Abs(const T &x) {
  return (x < 0 ? -x : x);
}
const int base = 16;
const long long INF = (long long)1e18 + 7LL;
long long comb[175][175];
long long f[175][175];
int cnt[175], lim;
long long pos;
void prepare(void) {
  for (int i = 0, _n = (175); i < _n; i = i + 1) comb[0][i] = 1;
  for (int i = (1), _b = (175 - 1); i <= _b; i = i + 1)
    for (int j = (1), _b = (175 - 1); j <= _b; j = j + 1) {
      if (i == j) comb[i][j] = 1;
      if (i < j) {
        comb[i][j] = comb[i][j - 1] + comb[i - 1][j - 1];
        minimize(comb[i][j], INF);
      }
    }
}
char getDigit(int x) { return x < 10 ? x + '0' : x - 10 + 'a'; }
long long product(long long a, long long b) {
  if (a == 0 || b == 0) return 0;
  return INF / a <= b ? INF : a * b;
}
long long cntWay(int length) {
  memset(f, 0, sizeof f);
  f[0][0] = 1;
  for (int i = 0, _n = (base); i < _n; i = i + 1)
    for (int j = 0, _n = (length + 1); j < _n; j = j + 1)
      if (f[i][j] > 0)
        for (int k = 0, _n = (cnt[i] + 1); k < _n; k = k + 1)
          if (j + k <= length) {
            f[i + 1][j + k] += product(f[i][j], comb[k][j + k]);
            minimize(f[i + 1][j + k], INF);
          }
  return f[base][length];
}
long long cntWayDigit(int dig) {
  long long res = 0;
  for (int i = (1), _b = (base - 1); i <= _b; i = i + 1)
    if (cnt[i] > 0) {
      cnt[i]--;
      res += cntWay(dig - 1);
      cnt[i]++;
    }
  return res;
}
void process(long long p, int l) {
  pos = p;
  lim = l;
  for (int i = 0, _n = (base); i < _n; i = i + 1) cnt[i] = lim;
  int numDigit = 1;
  while (true) {
    long long tmp = cntWayDigit(numDigit);
    if (pos > tmp) {
      pos -= tmp;
      numDigit++;
    } else
      break;
  }
  string digits;
  for (int love = 0, _n = (numDigit); love < _n; love = love + 1) {
    for (int i = (love == 0 ? 1 : 0), _b = (base - 1); i <= _b; i = i + 1)
      if (cnt[i] > 0) {
        cnt[i]--;
        long long tmp = cntWay(numDigit - love - 1);
        if (tmp >= pos) {
          digits.push_back(getDigit(i));
          break;
        } else {
          pos -= tmp;
          cnt[i]++;
        }
      }
  }
  cout << digits << endl;
}
int main(void) {
  prepare();
  long long pos;
  int lim;
  cin >> pos >> lim;
  process(pos, lim);
  return 0;
}
