#include <bits/stdc++.h>
long long K, T, d;
long long rest[17];
long long C[11][11], dp[21][17];
inline long long min(long long a, long long b) { return a < b ? a : b; }
void initC() {
  C[0][0] = 1;
  for (long long i = 1; i <= 10; i++) {
    C[i][0] = 1;
    for (long long j = 1; j <= i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  }
}
long long digital_dp(long long deep) {
  for (long long i = 1; i <= deep; i++) {
    dp[i][0] = (rest[0] >= i);
    for (long long j = 1; j < 16; j++) {
      dp[i][j] = 0;
      for (long long k = 0; k <= min(i, rest[j]); k++)
        dp[i][j] += dp[i - k][j - 1] * C[i][k];
    }
  }
  return dp[deep][15];
}
void print(long long x) {
  if (x < 10)
    putchar(x + '0');
  else
    putchar(x - 10 + 'a');
}
void dfs(long long deep) {
  if (deep == 0) return;
  for (int i = 1 - (deep != d); i < 16; i++) {
    if (rest[i] == 0) continue;
    rest[i]--;
    long long sum = digital_dp(deep - 1);
    if (sum >= K) {
      print(i);
      dfs(deep - 1);
      return;
    } else {
      K -= sum;
      rest[i]++;
    }
  }
}
int main() {
  scanf("%I64d%I64d", &K, &T);
  initC();
  for (long long i = 0; i < 16; i++) rest[i] = T;
  long long deep = 1;
  for (long long i = 0; i < 16; i++) dp[0][i] = 1;
  while (true) {
    rest[1]--;
    long long sum = digital_dp(deep - 1) * 15;
    rest[1]++;
    if (sum >= K) break;
    K -= sum;
    deep++;
  }
  d = deep;
  dfs(deep);
  return 0;
}
