#include <bits/stdc++.h>
using namespace std;
const int N = 16;
const char s[N] = {'0', '1', '2', '3', '4', '5', '6', '7',
                   '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
long long k, t, D, C[N][N], f[N][N], res[N];
char Ans[N];
long long Dp(int M) {
  if (!M) return 1;
  memset(f, 0, sizeof(f));
  for (int i = 0; i < N; i++)
    for (int j = 1; j <= res[i]; j++) f[j][i] = 1;
  for (int i = 1; i < M; i++)
    for (int j = 0; j < N; j++) {
      if (!f[i][j]) continue;
      for (int k = j + 1; k < N; k++)
        for (int len = 1; len <= res[k]; len++) {
          if (i + len > M) break;
          f[i + len][k] += f[i][j] * C[i + len][len];
        }
    }
  long long ret = 0;
  for (int i = 0; i < N; i++) ret += f[M][i];
  return ret;
}
int main() {
  cin >> k >> t;
  C[0][0] = 1;
  for (int i = 1; i < N; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  for (int i = 0; i < N; i++) res[i] = t;
  res[1] = t - 1;
  for (int i = 1; i < N; i++) {
    long long ret = Dp(i - 1) * 15LL;
    if (k > ret)
      k -= ret;
    else {
      D = i;
      break;
    }
  }
  res[1] = t;
  for (int i = D; i; i--) {
    int Start = (i == D) ? 1 : 0;
    for (int j = Start; j < N; j++) {
      if (!res[j]) continue;
      --res[j];
      long long ret = Dp(i - 1);
      if (k > ret)
        k -= ret, ++res[j];
      else {
        putchar(s[j]);
        break;
      }
    }
  }
  return 0;
}
