#include <bits/stdc++.h>
using namespace std;
long long c[20][20];
int k, t, deep, a[20];
long long f[20][20];
long long size;
void pre() {
  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] + c[i - 1][j - 1];
  }
}
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 == deep ? 2 : 1; i <= 16; i++) {
    if (a[i] == 0) continue;
    a[i]--;
    size = dp(x - 1);
    if (size >= k) {
      prt(i - 1);
      dfs(k, x - 1);
      break;
    }
    k -= size;
    a[i]++;
  }
}
int main() {
  scanf("%d%d", &k, &t);
  pre();
  for (int i = 1; i <= 16; i++) a[i] = t;
  deep = 1;
  while (1) {
    a[2]--;
    size = dp(deep - 1) * 15;
    a[2]++;
    if (size >= k) break;
    deep++;
    k -= size;
  }
  dfs(k, deep);
}
