#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
int fac[11], t;
void init() {
  fac[0] = 1;
  for (int(i) = 1; (i) <= (int)(10); (i)++) fac[i] = fac[i - 1] * i;
}
int com(int n, int m) {
  if (n < m) return 0;
  return fac[n] / fac[m] / fac[n - m];
}
int dp[20][20], cnt[20];
string str = "0123456789abcdef";
void cal(int L) {
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int(i) = 1; (i) <= (int)(16); (i)++) {
    for (int j = 0; j <= L; j++) {
      for (int x = 0; x <= j; x++)
        if (j - x <= cnt[i]) dp[i][j] += dp[i - 1][x] * com(L - x, j - x);
    }
  }
}
void wk(int len) {
  if (len == 0) exit(0);
  for (int(j) = 0; (j) < (int)(16); (j)++)
    if (cnt[j + 1]) {
      cnt[j + 1]--;
      cal(len - 1);
      int gg = dp[16][len - 1];
      if (gg < k)
        k -= gg;
      else {
        cout << str[j];
        wk(len - 1);
      }
      cnt[j + 1]++;
    }
}
void fmain() {
  scanf("%d%d", &k, &t);
  init();
  for (int(i) = 1; (i) <= (int)(16); (i)++) cnt[i] = t;
  for (int(i) = 1; (i) <= (int)(10); (i)++) {
    for (int j = 1; j < 16; j++) {
      cnt[j + 1]--;
      cal(i - 1);
      int gg = dp[16][i - 1];
      if (gg < k) {
        k -= gg;
      } else {
        cout << str[j];
        wk(i - 1);
      }
      cnt[j + 1]++;
    }
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain();
  }
  return 0;
}
