#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
const int N = 21;
long long k, t, dep;
long long c[N][N], f[N][N];
int a[23], num[N];
long long dp(int x) {
  for (int i = 0; i <= 16; i++) f[0][i] = 1;
  for (int i = 1; i <= x; i++)
    for (int j = 1; j <= 16; j++) {
      f[i][j] = 0;
      for (int k = 0; k <= min(i, a[j]); k++)
        f[i][j] += f[i - k][j - 1] * c[i][k];
    }
  return f[x][16];
}
void prt(int x) {
  if (x < 10)
    putchar(x + '0');
  else
    putchar(x - 10 + 'a');
}
void dfs(int k, int x) {
  if (x == 0) return;
  for (int i = (x == dep) ? 2 : 1; i <= 16; i++) {
    if (a[i] == 0) continue;
    a[i]--;
    long long size = dp(x - 1);
    if (size >= k) {
      prt(i - 1);
      dfs(k, x - 1);
      break;
    }
    k = k - size;
    a[i]++;
  }
}
int main() {
  k = read();
  t = read();
  for (int i = 1; i <= 16; i++) a[i] = t;
  c[1][0] = c[1][1] = 1;
  for (int i = 2; i <= 10; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  }
  dep = 1;
  while (1) {
    a[2]--;
    long long size = dp(dep - 1) * 15;
    a[2]++;
    if (size >= k) break;
    dep++, k -= size;
  }
  dfs(k, dep);
  return 0;
}
