#include <bits/stdc++.h>
using namespace std;
const int N = 20 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T& a, S b) {
  a += b;
  if (a >= mod) a -= mod;
}
template <class T, class S>
inline void sub(T& a, S b) {
  a -= b;
  if (a < 0) a += mod;
}
template <class T, class S>
inline bool chkmax(T& a, S b) {
  return a < b ? a = b, true : false;
}
template <class T, class S>
inline bool chkmin(T& a, S b) {
  return a > b ? a = b, true : false;
}
long long F[18];
long long dp[16][18];
long double dp2[16][18];
int c[16];
int ans[17];
int k, t;
long long getDp(int n, int* c) {
  if (n == 0) return 1;
  memset(dp, 0, sizeof(dp));
  memset(dp2, 0, sizeof(dp2));
  for (int i = 0; i <= c[0]; i++) dp[0][i] = 1, dp2[17][18];
  for (int i = 0; i < 15; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= c[i + 1]; k++) {
        if (j + k > n) continue;
        dp[i + 1][j + k] += F[j + k] / F[j] / F[k] * dp[i][j];
        dp2[i + 1][j + k] +=
            (long double)1.0 * F[j + k] / F[j] / F[k] * dp2[i][j];
      }
    }
  }
  if (dp2[15][n] > 1e10) return inf;
  return dp[15][n];
}
char print(int x) {
  if (x <= 9)
    return '0' + x;
  else
    return 'a' + (x - 10);
}
int main() {
  for (int i = F[0] = 1; i <= 17; i++) F[i] = F[i - 1] * i;
  scanf("%d%d", &k, &t);
  for (int i = 0; i <= 15; i++) c[i] = t;
  for (int len = 1; len <= 17; len++) {
    long long tot = 0;
    for (int j = 1; j <= 15; j++) {
      if (!c[j]) continue;
      c[j]--;
      int way = getDp(len - 1, c);
      if (way < k)
        k -= way, c[j]++, tot += way;
      else {
        ans[1] = j;
        break;
      }
    }
    if (!ans[1]) continue;
    for (int i = 2; i <= len; i++) {
      for (int j = 0; j <= 15; j++) {
        if (!c[j]) continue;
        c[j]--;
        int way = getDp(len - i, c);
        if (way < k)
          k -= way, c[j]++;
        else {
          ans[i] = j;
          break;
        }
      }
    }
    for (int i = 1; i <= len; i++) printf("%c", print(ans[i]));
    puts("");
    return 0;
  }
  return 0;
}
