#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int MAXN = 1e5 + 5;
const int MAXM = 2e6 + 5;
const int MOD = 1e9 + 7;
int sgn(double x) {
  if (fabs(x) < eps) return 0;
  if (x < 0)
    return -1;
  else
    return 1;
}
long long pw(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void inc(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
void dec(long long &a, long long b) {
  a -= b;
  if (a < 0) a += MOD;
}
int mul(int x, int y) {
  long long z = 1ll * x * y;
  return z - z / MOD * MOD;
}
int k, t, up[16];
long long dp[16][205], c[205][15];
void init() {
  for (int i = 0; i < 205; i++) {
    c[i][0] = 1;
    for (int j = 1; j < min(i, 10) + 1; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
}
long long gao(int len) {
  for (int i = 0; i < 16; i++)
    for (int j = 0; j < len + 1; j++) {
      dp[i][j] = 0;
    }
  for (int j = 0; j < up[0] + 1; j++) {
    dp[0][j] = c[len][j];
  }
  for (int i = 1; i < 16; i++)
    for (int j = 0; j < len + 1; j++)
      for (int k = 0; k < min(j, up[i]) + 1; k++) {
        dp[i][j] += dp[i - 1][j - k] * c[len - (j - k)][k];
      }
  return dp[15][len];
}
char _hex[] = "0123456789abcdef";
int main() {
  init();
  scanf("%d%d", &k, &t);
  for (int i = 0; i < 16; i++) up[i] = t;
  int len = 1;
  long long s;
  for (;; len++) {
    if (len == 1)
      s = 15;
    else {
      s = 0;
      for (int i = 1; i < 16; i++) {
        up[i]--;
        s += gao(len - 1);
        up[i]++;
      }
    }
    if (s >= k) break;
    k -= s;
  }
  bool fs = true;
  for (; len > 1; len--) {
    for (int i = 0; i < 16; i++) {
      if (fs && !i) continue;
      fs = false;
      up[i]--;
      s = gao(len - 1);
      if (s >= k) {
        printf("%c", _hex[i]);
        break;
      }
      k -= s;
      up[i]++;
    }
  }
  for (int i = 0; i < 16; i++) {
    if (fs && !i) continue;
    if (up[i]) k--;
    if (!k) {
      printf("%c\n", _hex[i]);
      break;
    }
  }
}
