#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
long long po(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
long long fac[25], val[25], ans[25];
long long dp[25][25];
long long C(long long n, long long m) { return fac[n] / fac[m] / fac[n - m]; }
void init() {
  fac[0] = 1;
  for (long long i = 1; i <= 20; i++) {
    fac[i] = fac[i - 1] * i;
  }
}
long long get(long long x) {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= 16; i++) {
    for (int len = 0; len <= x; len++) {
      for (int add = 0; add + len <= x && add <= val[i]; add++) {
        dp[i][len + add] += dp[i - 1][len] * C(len + add, add);
      }
    }
  }
  return dp[16][x];
}
long long k, t;
void solve() {
  scanf("%lld%lld", &k, &t);
  for (int i = 1; i <= 16; i++) {
    val[i] = t;
  }
  int bit = 1;
  k--;
  while (true) {
    long long res = 0;
    for (int i = 2; i <= 16; i++) {
      val[i]--;
      res += get(bit - 1);
      val[i]++;
    }
    if (k >= res) {
      k -= res;
      bit++;
    } else {
      break;
    }
  }
  long long tmp = k;
  long long n = tmp;
  for (int h = bit; h >= 1; h--) {
    n = tmp;
    for (int g = (h == bit ? 2 : 1); g <= 16; g++) {
      if (val[g] <= 0) continue;
      val[g]--;
      long long res = get(h - 1);
      if (res <= n) {
        n -= res;
      } else {
        ans[h] = g;
        break;
      }
      val[g]++;
    }
    tmp = n;
  }
  for (int i = bit; i >= 1; i--) {
    if (ans[i] <= 10) {
      printf("%d", ans[i] - 1);
    } else {
      printf("%c", char(ans[i] - 10 + 'a' - 1));
    }
  }
}
int main() {
  init();
  solve();
  return 0;
}
