#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
long long fact[21], dp[16][16];
int mx_can[16], t, flen;
long long ncr(int n, int r) {
  long long ans = fact[n] / fact[r];
  ans = ans / fact[n - r];
  return ans;
}
long long rec(int pos, int num) {
  if (pos <= 0) return 1;
  if (num == 16) return 0;
  long long& ret = dp[pos][num];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i <= min(pos, mx_can[num]); i++) {
    ret += (ncr(flen - pos + i, i) * rec(pos - i, num + 1));
  }
  return ret;
}
int main() {
  fact[0] = 1;
  for (long long i = 1; i <= 20; i++) fact[i] = fact[i - 1] * i;
  long long k, tmp, w = 1;
  scanf("%lld", &k);
  scanf("%d", &t);
  for (int i = 0; i < 16; i++) mx_can[i] = t;
  mx_can[0]--;
  while (w) {
    memset(dp, -1, sizeof(dp));
    flen = w - 1;
    tmp = rec(w - 1, 0) * 15LL;
    if (tmp < k)
      k -= tmp;
    else
      break;
    w++;
  }
  mx_can[0]++;
  int ans[30];
  for (int i = w; i > 0; i--) {
    for (int j = (int)(i == w); j < 16; j++) {
      if (mx_can[j] == 0) continue;
      memset(dp, -1, sizeof(dp));
      mx_can[j]--;
      flen = i - 1;
      tmp = rec(i - 1, 0);
      if (tmp < k)
        k -= tmp;
      else {
        if (j >= 10)
          printf("%c", 'a' + (j - 10));
        else
          printf("%d", j);
        break;
      }
      mx_can[j]++;
    }
  }
  printf("\n");
  return 0;
}
