#include <bits/stdc++.h>
using namespace std;
const int mx = 1e2 + 10;
const int H = 16;
long long c[mx][mx], k, t;
void solveC(int SIZE) {
  c[1][0] = c[1][1] = 1;
  for (int i = 2; i <= SIZE; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
}
long long len;
long long dp[mx][mx];
long long rest[mx];
long long ans[mx];
long long DP1(long long siz) {
  if (siz == 0) return 1;
  memset(dp, 0, sizeof(dp));
  for (long long i = 1; i <= H; i++) {
    dp[i - 1][0] = 1;
    for (long long j = 1; j <= siz; j++) {
      for (long long s = 0; s <= rest[i - 1] && s <= j; s++) {
        dp[i][j] += dp[i - 1][j - s] * c[j][s];
      }
    }
  }
  return dp[H][siz];
}
long long DP2(long long siz) {
  if (siz == 0) return 1;
  long long res = 0;
  for (long long i = 1; i < H; i++) {
    rest[i]--;
    res += DP1(siz - 1);
    rest[i]++;
  }
  return res;
}
void solve() {
  solveC(36);
  scanf("%I64d %I64d", &k, &t);
  for (long long i = 0; i < H; i++) rest[i] = t;
  while (1) {
    len++;
    long long curr = DP2(len);
    if (curr >= k) break;
    k -= curr;
  }
  for (long long i = len; i >= 1; i--) {
    long long fir = (i == len) ? 1 : 0;
    for (; fir < H; fir++) {
      if (rest[fir] == 0) continue;
      rest[fir]--;
      long long curr = DP1(i - 1);
      if (curr < k) {
        rest[fir]++;
        k -= curr;
        continue;
      }
      ans[i] = fir;
      break;
    }
  }
  for (long long i = len; i >= 1; i--) {
    printf("%c",
           ans[i] < 10 ? (char)(ans[i] + '0') : (char)(ans[i] - 10 + 'a'));
  }
  puts("");
}
int main() {
  solve();
  return 0;
}
