#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
long long C[2010][2010];
long long K, T;
long long num[30];
long long limit[30];
long long f[17][30];
long long len;
long long ans[30];
char h[] = "0123456789abcdefghijklmn";
long long dp(int lim);
void cope_c();
int main() {
  cope_c();
  K = rd(), T = rd();
  for (int i = 1; i <= 16; ++i) limit[i] = T;
  num[0] = 0;
  for (int i = 1; i <= 15; ++i) {
    --limit[2];
    num[i] = dp(i - 1) * 15;
    num[i] += num[i - 1];
    ++limit[2];
    if (num[i] >= K) {
      len = i;
      break;
    }
  }
  K -= num[len - 1];
  for (int i = len; i >= 1; --i) {
    long long sum = 0;
    for (int j = 1; j <= 16; ++j) {
      if (i == len && j == 1) continue;
      if (!limit[j]) continue;
      --limit[j];
      sum = dp(i - 1);
      ++limit[j];
      if (sum < K) {
        K -= sum;
      } else {
        ans[i] = j - 1;
        --limit[j];
        break;
      }
    }
  }
  for (int i = len; i; --i) printf("%c", h[ans[i]]);
  return 0;
}
void cope_c() {
  C[0][0] = 1;
  for (int i = 1; i <= 30; ++i) {
    for (int j = 0; j <= i; ++j) {
      C[i][j] = C[i - 1][j] + (j ? C[i - 1][j - 1] : 0);
    }
  }
}
long long dp(int lim) {
  if (!lim) return 1;
  memset(f, 0, sizeof f);
  for (int i = 0; i <= 16; ++i) f[i][0] = 1;
  for (int i = 1; i <= 16; ++i) {
    for (int j = 1; j <= lim; ++j) {
      for (int k = 0; k <= limit[i] && k <= lim; ++k) {
        f[i][j] += f[i - 1][j - k] * C[j][k];
      }
    }
  }
  return f[16][lim];
}
