#include <bits/stdc++.h>
using namespace std;
inline int readint() {
  int a = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -f;
  for (; '0' <= c && c <= '9'; c = getchar())
    a = (a << 3) + (a << 1) + (c ^ 48);
  return a * f;
}
template <typename T>
void getMax(T &a, const T &b) {
  if (a < b) a = b;
}
template <typename T>
void getMin(T &a, const T &b) {
  if (b < a) a = b;
}
int k, n;
long long comb[100][100];
long long dp[16][100];
int cnt[16];
void clear(int len, int t = 15) {
  for (int i = 1; i <= t; ++i)
    for (int j = 1; j <= len; ++j) dp[i][j] = -1;
}
long long getNum(int len, int t = 15) {
  if (len == 0) return 1;
  if (t == 0) return 0;
  long long &now = dp[t][len];
  if (now != -1) return now;
  now = 0;
  for (int o = 0; o <= cnt[t] && o <= len; ++o)
    now += getNum(len - o, t - 1) * comb[len][o];
  return now;
}
int ans[100], len;
int main() {
  k = readint(), n = readint();
  for (int i = 0; i < 100; ++i)
    for (int j = comb[i][0] = 1; j <= i; ++j)
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
  for (int i = 0; i < 16; ++i) cnt[i] = n;
  clear(99);
  while (++len) {
    long long res = 0;
    for (int o = 0; o <= cnt[0] && o < len; ++o)
      res += getNum(len - o) * comb[len - 1][o];
    if (res >= k) break;
    k -= res;
  }
  for (int i = 1; i <= len; ++i)
    for (int j = (i == 1); j < 16; ++j) {
      if (cnt[j] == 0) continue;
      --cnt[j], ans[i] = j;
      clear(len - i);
      long long tmp = 0;
      for (int o = 0; o <= cnt[0] && o <= len - i; ++o)
        tmp += getNum(len - i - o) * comb[len - i][o];
      if (tmp >= k) break;
      k -= tmp, ++cnt[j];
    }
  for (int i = 1; i <= len; ++i)
    if (ans[i] < 10)
      putchar(ans[i] + '0');
    else
      putchar(ans[i] + 'a' - 10);
  putchar('\n');
  return 0;
}
